Built motion from commit (unavailable).|2.5.13
[motion2.git] / server / api / trunk / trunk.controller.js
index 702e8bb..a324660 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xafdc=['length','hasOwnProperty','nolimit','limit','sort','where','pick','merge','type','filter','options','includeAll','findAll','rows','show','params','keys','find','clone','include','createdAt','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','create','readFileSync','join','root','server/files/templates/trunk.ejs','utf8','server/files/templates/registry.ejs','render','registry','writeFileSync','/etc/asterisk/sip_xcally_registers.conf','Reload','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','/etc/asterisk/sip_xcally_trunks.conf','chan_sip.so','html-pdf','eml-format','zip-dir','fast-json-patch','moment','mustache','sox','to-csv','lodash','squel','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','jayson/promise','client','request','then','info','request\x20sent','debug','stringify','error','code','Trunk,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','count','offset','set','apply','save','update','destroy','get','Trunks','UserProfileResource','stack','name','map','Trunk','rawAttributes','key','model','query','filters','intersection','attributes','fields'];(function(_0x418118,_0x38550d){var _0x548dad=function(_0x20f547){while(--_0x20f547){_0x418118['push'](_0x418118['shift']());}};_0x548dad(++_0x38550d);}(_0xafdc,0x163));var _0xcafd=function(_0x382053,_0x40af67){_0x382053=_0x382053-0x0;var _0x421fe5=_0xafdc[_0x382053];return _0x421fe5;};'use strict';var pdf=require(_0xcafd('0x0'));var emlformat=require(_0xcafd('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xcafd('0x2'));var jsonpatch=require(_0xcafd('0x3'));var rp=require('request-promise');var moment=require(_0xcafd('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xcafd('0x5'));var util=require('util');var path=require('path');var sox=require(_0xcafd('0x6'));var csv=require(_0xcafd('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xcafd('0x8'));var squel=require(_0xcafd('0x9'));var crypto=require('crypto');var jsforce=require(_0xcafd('0xa'));var deskjs=require(_0xcafd('0xb'));var toCsv=require(_0xcafd('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xcafd('0xc'));var authService=require(_0xcafd('0xd'));var qs=require(_0xcafd('0xe'));var as=require(_0xcafd('0xf'));var hardwareService=require(_0xcafd('0x10'));var logger=require(_0xcafd('0x11'))(_0xcafd('0x12'));var utils=require(_0xcafd('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0xcafd('0x14'));var db=require('../../mysqldb')['db'];var jayson=require(_0xcafd('0x15'));var client=jayson[_0xcafd('0x16')]['http']({'port':0x232a});function respondWithRpcPromise(_0x8eb38e,_0x2b9832,_0x4afe7d,_0x4fd525){return new BPromise(function(_0x5e247c,_0x891ac3){var _0x43165a=_0x4fd525||client;return _0x43165a[_0xcafd('0x17')](_0x8eb38e,_0x4afe7d)[_0xcafd('0x18')](function(_0x570219){logger[_0xcafd('0x19')]('Trunk,\x20%s,\x20%s',_0x2b9832,_0xcafd('0x1a'));logger[_0xcafd('0x1b')]('Trunk,\x20%s,\x20%s,\x20%s',_0x2b9832,_0xcafd('0x1a'),JSON[_0xcafd('0x1c')](_0x570219));if(_0x570219['error']){if(_0x570219[_0xcafd('0x1d')][_0xcafd('0x1e')]===0x1f4){logger[_0xcafd('0x1d')](_0xcafd('0x1f'),_0x2b9832,_0x570219[_0xcafd('0x1d')]['message']);return _0x891ac3(_0x570219[_0xcafd('0x1d')]['message']);}logger[_0xcafd('0x1d')](_0xcafd('0x1f'),_0x2b9832,_0x570219[_0xcafd('0x1d')]['message']);return _0x5e247c(_0x570219[_0xcafd('0x1d')][_0xcafd('0x20')]);}else{logger[_0xcafd('0x19')](_0xcafd('0x1f'),_0x2b9832,_0xcafd('0x1a'));_0x5e247c(_0x570219[_0xcafd('0x21')][_0xcafd('0x20')]);}})[_0xcafd('0x22')](function(_0x418b51){logger[_0xcafd('0x1d')]('Trunk,\x20%s,\x20%s',_0x2b9832,_0x418b51);_0x891ac3(_0x418b51);});});}function respondWithStatusCode(_0x463699,_0x3e7562){_0x3e7562=_0x3e7562||0xcc;return function(_0x1c18df){if(_0x1c18df){return _0x463699[_0xcafd('0x23')](_0x3e7562);}return _0x463699[_0xcafd('0x24')](_0x3e7562)[_0xcafd('0x25')]();};}function respondWithResult(_0x505c9a,_0x137db5){_0x137db5=_0x137db5||0xc8;return function(_0x3cc114){if(_0x3cc114){return _0x505c9a[_0xcafd('0x24')](_0x137db5)[_0xcafd('0x26')](_0x3cc114);}};}function respondWithFilteredResult(_0x280295,_0x412e52){return function(_0x54b295){if(_0x54b295){var _0xb590b2=_0x54b295[_0xcafd('0x27')],_0x4c5bb1=_0x412e52[_0xcafd('0x28')],_0x317670=_0x412e52[_0xcafd('0x28')]+_0x412e52['limit'],_0x14ba5a;if(_0x317670>=_0xb590b2){_0x317670=_0xb590b2;_0x14ba5a=0xc8;}else{_0x14ba5a=0xce;}_0x280295[_0xcafd('0x24')](_0x14ba5a);return _0x280295[_0xcafd('0x29')]('Content-Range',_0x4c5bb1+'-'+_0x317670+'/'+_0xb590b2)['json'](_0x54b295);}return null;};}function patchUpdates(_0x45b455){return function(_0x156216){try{jsonpatch[_0xcafd('0x2a')](_0x156216,_0x45b455,!![]);}catch(_0x38212f){return BPromise['reject'](_0x38212f);}return _0x156216[_0xcafd('0x2b')]();};}function saveUpdates(_0x1a757c,_0x21f09c){return function(_0x3c646b){if(_0x3c646b){return _0x3c646b[_0xcafd('0x2c')](_0x1a757c)[_0xcafd('0x18')](function(_0xe4d62c){return _0xe4d62c;});}return null;};}function removeEntity(_0x5eeb8d,_0x190dbb){return function(_0x2f0abf){if(_0x2f0abf){return _0x2f0abf[_0xcafd('0x2d')]()[_0xcafd('0x18')](function(){var _0x50b797=_0x2f0abf[_0xcafd('0x2e')]({'plain':!![]});var _0x5304e8=_0xcafd('0x2f');return db[_0xcafd('0x30')]['destroy']({'where':{'type':_0x5304e8,'resourceId':_0x50b797['id']}})[_0xcafd('0x18')](function(){return _0x2f0abf;});})[_0xcafd('0x18')](function(){_0x5eeb8d['status'](0xcc)[_0xcafd('0x25')]();});}};}function handleEntityNotFound(_0x381a90,_0x35486b){return function(_0x5088e7){if(!_0x5088e7){_0x381a90[_0xcafd('0x23')](0x194);}return _0x5088e7;};}function handleError(_0x55690c,_0x4e0b00){_0x4e0b00=_0x4e0b00||0x1f4;return function(_0x33f52c){logger[_0xcafd('0x1d')](_0x33f52c[_0xcafd('0x31')]);if(_0x33f52c[_0xcafd('0x32')]){delete _0x33f52c[_0xcafd('0x32')];}_0x55690c[_0xcafd('0x24')](_0x4e0b00)['send'](_0x33f52c);};}exports['index']=function(_0x91c11c,_0x3c63cf){var _0x1628c4={},_0xa35b84={},_0x22fcce={'count':0x0,'rows':[]};var _0x2fda0a=_[_0xcafd('0x33')](db[_0xcafd('0x34')][_0xcafd('0x35')],function(_0x4f3870){return{'name':_0x4f3870['fieldName'],'type':_0x4f3870['type'][_0xcafd('0x36')]};});_0xa35b84[_0xcafd('0x37')]=_[_0xcafd('0x33')](_0x2fda0a,_0xcafd('0x32'));_0xa35b84[_0xcafd('0x38')]=_['keys'](_0x91c11c[_0xcafd('0x38')]);_0xa35b84[_0xcafd('0x39')]=_[_0xcafd('0x3a')](_0xa35b84[_0xcafd('0x37')],_0xa35b84['query']);_0x1628c4[_0xcafd('0x3b')]=_[_0xcafd('0x3a')](_0xa35b84['model'],qs['fields'](_0x91c11c[_0xcafd('0x38')][_0xcafd('0x3c')]));_0x1628c4[_0xcafd('0x3b')]=_0x1628c4['attributes'][_0xcafd('0x3d')]?_0x1628c4[_0xcafd('0x3b')]:_0xa35b84[_0xcafd('0x37')];if(!_0x91c11c[_0xcafd('0x38')][_0xcafd('0x3e')](_0xcafd('0x3f'))){_0x1628c4[_0xcafd('0x40')]=qs[_0xcafd('0x40')](_0x91c11c[_0xcafd('0x38')][_0xcafd('0x40')]);_0x1628c4['offset']=qs[_0xcafd('0x28')](_0x91c11c[_0xcafd('0x38')][_0xcafd('0x28')]);}_0x1628c4['order']=qs[_0xcafd('0x41')](_0x91c11c[_0xcafd('0x38')][_0xcafd('0x41')]);_0x1628c4[_0xcafd('0x42')]=qs[_0xcafd('0x39')](_[_0xcafd('0x43')](_0x91c11c[_0xcafd('0x38')],_0xa35b84[_0xcafd('0x39')]),_0x2fda0a);if(_0x91c11c['query']['filter']){_0x1628c4['where']=_[_0xcafd('0x44')](_0x1628c4[_0xcafd('0x42')],{'$or':_[_0xcafd('0x33')](_0x2fda0a,function(_0x2be67d){if(_0x2be67d[_0xcafd('0x45')]!=='VIRTUAL'){var _0x7620a3={};_0x7620a3[_0x2be67d[_0xcafd('0x32')]]={'$like':'%'+_0x91c11c[_0xcafd('0x38')][_0xcafd('0x46')]+'%'};return _0x7620a3;}})});}_0x1628c4=_['merge']({},_0x1628c4,_0x91c11c[_0xcafd('0x47')]);var _0x304ab4={'where':_0x1628c4[_0xcafd('0x42')]};return db[_0xcafd('0x34')]['count'](_0x304ab4)['then'](function(_0x18568e){_0x22fcce[_0xcafd('0x27')]=_0x18568e;if(_0x91c11c['query'][_0xcafd('0x48')]){_0x1628c4['include']=[{'all':!![]}];}return db[_0xcafd('0x34')][_0xcafd('0x49')](_0x1628c4);})[_0xcafd('0x18')](function(_0x4e3696){_0x22fcce[_0xcafd('0x4a')]=_0x4e3696;return _0x22fcce;})['then'](respondWithFilteredResult(_0x3c63cf,_0x1628c4))['catch'](handleError(_0x3c63cf,null));};exports[_0xcafd('0x4b')]=function(_0x5a4044,_0xa6924f){var _0x55d792={'raw':![],'where':{'id':_0x5a4044[_0xcafd('0x4c')]['id']}},_0x1adc73={};_0x1adc73['model']=_[_0xcafd('0x4d')](db[_0xcafd('0x34')][_0xcafd('0x35')]);_0x1adc73[_0xcafd('0x38')]=_['keys'](_0x5a4044[_0xcafd('0x38')]);_0x1adc73[_0xcafd('0x39')]=_['intersection'](_0x1adc73['model'],_0x1adc73[_0xcafd('0x38')]);_0x55d792[_0xcafd('0x3b')]=_[_0xcafd('0x3a')](_0x1adc73['model'],qs[_0xcafd('0x3c')](_0x5a4044['query'][_0xcafd('0x3c')]));_0x55d792[_0xcafd('0x3b')]=_0x55d792[_0xcafd('0x3b')][_0xcafd('0x3d')]?_0x55d792[_0xcafd('0x3b')]:_0x1adc73['model'];if(_0x5a4044[_0xcafd('0x38')][_0xcafd('0x48')]){_0x55d792['include']=[{'all':!![]}];}_0x55d792=_['merge']({},_0x55d792,_0x5a4044[_0xcafd('0x47')]);return db[_0xcafd('0x34')][_0xcafd('0x4e')](_0x55d792)['then'](handleEntityNotFound(_0xa6924f,null))[_0xcafd('0x18')](respondWithResult(_0xa6924f,null))['catch'](handleError(_0xa6924f,null));};exports[_0xcafd('0x4f')]=function(_0x54972b,_0x450de6){var _0x2cc222={'where':{'id':_0x54972b['params']['id']}},_0x439b0d={};_0x439b0d[_0xcafd('0x37')]=_[_0xcafd('0x4d')](db[_0xcafd('0x34')][_0xcafd('0x35')]);_0x2cc222[_0xcafd('0x3b')]=_[_0xcafd('0x3a')](_0x439b0d[_0xcafd('0x37')],qs[_0xcafd('0x3c')](_0x54972b[_0xcafd('0x38')][_0xcafd('0x3c')]));_0x2cc222['attributes']=_0x2cc222[_0xcafd('0x3b')][_0xcafd('0x3d')]?_0x2cc222['attributes']:_0x439b0d['model'];if(_0x54972b[_0xcafd('0x38')][_0xcafd('0x48')]){_0x2cc222[_0xcafd('0x50')]=[{'all':!![]}];}_0x2cc222=_['merge']({},_0x2cc222,_0x54972b[_0xcafd('0x47')]);return db['Trunk']['find'](_0x2cc222)[_0xcafd('0x18')](handleEntityNotFound(_0x450de6,null))[_0xcafd('0x18')](function(_0x1419fb){if(_0x1419fb){var _0x5156d5=_0x1419fb['get']({'plain':!![]});_0x5156d5=qs['omit'](_0x5156d5,['id',_0xcafd('0x51'),'updatedAt']);_0x54972b[_0xcafd('0x52')]=_['omit'](_0x54972b['body'],['id',_0xcafd('0x51'),'updatedAt']);return db[_0xcafd('0x34')]['create'](_[_0xcafd('0x44')](_0x5156d5,_0x54972b[_0xcafd('0x52')]),{'include':_0x54972b[_0xcafd('0x38')][_0xcafd('0x48')]?[{'all':!![]}]:undefined})[_0xcafd('0x18')](function(_0x382255){var _0x44d9e4=_0x54972b[_0xcafd('0x53')][_0xcafd('0x2e')]({'plain':!![]});if(!_0x44d9e4)throw new Error(_0xcafd('0x54'));if(_0x44d9e4[_0xcafd('0x55')]===_0xcafd('0x53')){var _0x5f2f10=_0x382255['get']({'plain':!![]});var _0xa39307='Trunks';return db[_0xcafd('0x56')][_0xcafd('0x4e')]({'where':{'name':_0xa39307,'userProfileId':_0x44d9e4[_0xcafd('0x57')]},'raw':!![]})['then'](function(_0x11df14){if(_0x11df14&&_0x11df14[_0xcafd('0x58')]===0x0){return db[_0xcafd('0x30')][_0xcafd('0x59')]({'name':_0x5f2f10[_0xcafd('0x32')],'resourceId':_0x5f2f10['id'],'type':_0x11df14['name'],'sectionId':_0x11df14['id']},{})[_0xcafd('0x18')](function(){return _0x382255;});}else{return _0x382255;}})[_0xcafd('0x22')](function(_0x3bcd99){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3bcd99);throw _0x3bcd99;});}return _0x382255;});}})[_0xcafd('0x18')](respondWithResult(_0x450de6,0xc9))[_0xcafd('0x22')](handleError(_0x450de6,null));};exports[_0xcafd('0x59')]=function(_0xeca33e,_0x13b683,_0x12449d){var _0x3318bc;return db[_0xcafd('0x34')][_0xcafd('0x59')](_0xeca33e[_0xcafd('0x52')],{'raw':!![]})[_0xcafd('0x18')](function(_0x5de862){_0x3318bc=_0x5de862;return db[_0xcafd('0x34')][_0xcafd('0x49')]({'raw':!![]});})[_0xcafd('0x18')](function(_0x3234d1){var _0x278fd6=fs[_0xcafd('0x5a')](path[_0xcafd('0x5b')](config[_0xcafd('0x5c')],_0xcafd('0x5d')),_0xcafd('0x5e'));var _0xcf9762=fs['readFileSync'](path[_0xcafd('0x5b')](config[_0xcafd('0x5c')],_0xcafd('0x5f')),_0xcafd('0x5e'));var _0x24b261=ejs[_0xcafd('0x60')](_0x278fd6,{'trunks':_0x3234d1||[]});fs['writeFileSync']('/etc/asterisk/sip_xcally_trunks.conf',_0x24b261);if(_0x3318bc[_0xcafd('0x61')]){var _0x4c5e5e=ejs[_0xcafd('0x60')](_0xcf9762,{'trunks':_0x3234d1||[]});fs[_0xcafd('0x62')](_0xcafd('0x63'),_0x4c5e5e);}})[_0xcafd('0x18')](function(){return respondWithRpcPromise(_0xcafd('0x64'),_0xcafd('0x59'),{'module':'chan_sip.so'});})[_0xcafd('0x18')](function(){var _0x4b3242=_0xeca33e[_0xcafd('0x53')][_0xcafd('0x2e')]({'plain':!![]});if(!_0x4b3242)throw new Error(_0xcafd('0x54'));if(_0x4b3242[_0xcafd('0x55')]===_0xcafd('0x53')){var _0x11a628=_0x3318bc[_0xcafd('0x2e')]({'plain':!![]});return db['UserProfileSection'][_0xcafd('0x4e')]({'where':{'name':'Trunks','userProfileId':_0x4b3242[_0xcafd('0x57')]},'raw':!![]})['then'](function(_0x55e3f7){if(_0x55e3f7&&_0x55e3f7['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x11a628[_0xcafd('0x32')],'resourceId':_0x11a628['id'],'type':_0x55e3f7['name'],'sectionId':_0x55e3f7['id']},{})[_0xcafd('0x18')](function(){return _0x3318bc;});}else{return _0x3318bc;}})['catch'](function(_0x5f3aad){logger[_0xcafd('0x1d')](_0xcafd('0x65'),_0x5f3aad);throw _0x5f3aad;});}return _0x3318bc;})[_0xcafd('0x18')](respondWithResult(_0x13b683,0xc9))[_0xcafd('0x22')](handleError(_0x13b683,null));};exports[_0xcafd('0x2c')]=function(_0x2e330a,_0x22dc33,_0x4fc1fd){var _0x1f6d7b;return db['Trunk']['find']({'where':{'id':_0x2e330a['params']['id']}})['then'](handleEntityNotFound(_0x22dc33,null))[_0xcafd('0x18')](saveUpdates(_0x2e330a[_0xcafd('0x52')],null))[_0xcafd('0x18')](function(_0x337d98){if(_0x337d98){_0x1f6d7b=_0x337d98;return db['Trunk'][_0xcafd('0x49')]({'raw':!![]});}})[_0xcafd('0x18')](function(_0x446f93){if(_0x446f93){var _0x203cd6=fs[_0xcafd('0x5a')](path[_0xcafd('0x5b')](config[_0xcafd('0x5c')],'server/files/templates/trunk.ejs'),_0xcafd('0x5e'));var _0x255475=fs[_0xcafd('0x5a')](path['join'](config[_0xcafd('0x5c')],'server/files/templates/registry.ejs'),_0xcafd('0x5e'));var _0x214c1d=ejs[_0xcafd('0x60')](_0x203cd6,{'trunks':_0x446f93||[]});fs[_0xcafd('0x62')](_0xcafd('0x66'),_0x214c1d);var _0x16e02f=ejs[_0xcafd('0x60')](_0x255475,{'trunks':_0x446f93||[]});fs[_0xcafd('0x62')](_0xcafd('0x63'),_0x16e02f);return respondWithRpcPromise('Reload',_0xcafd('0x2c'),{'module':'chan_sip.so'});}return null;})['then'](function(_0x1a11c3){if(_0x1a11c3){return _0x1f6d7b;}})[_0xcafd('0x18')](respondWithResult(_0x22dc33,null))['catch'](handleError(_0x22dc33,null));};exports['destroy']=function(_0x1370ed,_0x1619be,_0x417919){var _0x5e5c64;return db[_0xcafd('0x34')][_0xcafd('0x4e')]({'where':{'id':_0x1370ed[_0xcafd('0x4c')]['id']}})[_0xcafd('0x18')](handleEntityNotFound(_0x1619be,null))[_0xcafd('0x18')](removeEntity(_0x1619be,null))[_0xcafd('0x18')](function(){return db['Trunk'][_0xcafd('0x49')]({'raw':!![]});})['then'](function(_0x272f04){var _0x51fc1d=fs[_0xcafd('0x5a')](path['join'](config['root'],_0xcafd('0x5d')),_0xcafd('0x5e'));var _0xeea60a=fs['readFileSync'](path[_0xcafd('0x5b')](config[_0xcafd('0x5c')],_0xcafd('0x5f')),_0xcafd('0x5e'));var _0x4049de=ejs[_0xcafd('0x60')](_0x51fc1d,{'trunks':_0x272f04});var _0x5dc9ec=ejs[_0xcafd('0x60')](_0xeea60a,{'trunks':_0x272f04});fs[_0xcafd('0x62')](_0xcafd('0x66'),_0x4049de);fs['writeFileSync'](_0xcafd('0x63'),_0x5dc9ec);return respondWithRpcPromise('Reload',_0xcafd('0x2d'),{'module':_0xcafd('0x67')});})[_0xcafd('0x22')](handleError(_0x1619be,null));};
\ No newline at end of file
+var _0xff2b=['omit','createdAt','updatedAt','body','create','role','user','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','readFileSync','root','server/files/templates/trunk.ejs','server/files/templates/registry.ejs','utf8','render','writeFileSync','/etc/asterisk/sip_xcally_trunks.conf','registry','/etc/asterisk/sip_xcally_registers.conf','Reload','chan_sip.so','autoAssociation','join','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','util','sox','to-csv','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','jayson/promise','client','http','request','info','Trunk,\x20%s,\x20%s','request\x20sent','debug','stringify','code','error','message','catch','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','Trunks','end','stack','name','index','Trunk','rawAttributes','fieldName','type','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','includeAll','include','findAll','rows','show','merge','options','find','clone'];(function(_0x1aa3fe,_0x27c5fa){var _0x163cee=function(_0x2a1505){while(--_0x2a1505){_0x1aa3fe['push'](_0x1aa3fe['shift']());}};_0x163cee(++_0x27c5fa);}(_0xff2b,0x159));var _0xbff2=function(_0x5c854f,_0x557516){_0x5c854f=_0x5c854f-0x0;var _0x5e1f97=_0xff2b[_0x5c854f];return _0x5e1f97;};'use strict';var pdf=require(_0xbff2('0x0'));var emlformat=require(_0xbff2('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xbff2('0x2'));var jsonpatch=require(_0xbff2('0x3'));var rp=require(_0xbff2('0x4'));var moment=require(_0xbff2('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xbff2('0x6'));var path=require('path');var sox=require(_0xbff2('0x7'));var csv=require(_0xbff2('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xbff2('0x9'));var crypto=require(_0xbff2('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xbff2('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xbff2('0xc'));var Redis=require(_0xbff2('0xd'));var authService=require(_0xbff2('0xe'));var qs=require(_0xbff2('0xf'));var as=require(_0xbff2('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xbff2('0x11'))(_0xbff2('0x12'));var utils=require('../../config/utils');var config=require(_0xbff2('0x13'));var licenseUtil=require(_0xbff2('0x14'));var db=require('../../mysqldb')['db'];var jayson=require(_0xbff2('0x15'));var client=jayson[_0xbff2('0x16')][_0xbff2('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x31b35c,_0x194e79,_0x46d380,_0x99d874){return new BPromise(function(_0x19dfea,_0x293cd5){var _0x410541=_0x99d874||client;return _0x410541[_0xbff2('0x18')](_0x31b35c,_0x46d380)['then'](function(_0x11d689){logger[_0xbff2('0x19')](_0xbff2('0x1a'),_0x194e79,_0xbff2('0x1b'));logger[_0xbff2('0x1c')]('Trunk,\x20%s,\x20%s,\x20%s',_0x194e79,_0xbff2('0x1b'),JSON[_0xbff2('0x1d')](_0x11d689));if(_0x11d689['error']){if(_0x11d689['error'][_0xbff2('0x1e')]===0x1f4){logger[_0xbff2('0x1f')](_0xbff2('0x1a'),_0x194e79,_0x11d689[_0xbff2('0x1f')][_0xbff2('0x20')]);return _0x293cd5(_0x11d689[_0xbff2('0x1f')][_0xbff2('0x20')]);}logger[_0xbff2('0x1f')](_0xbff2('0x1a'),_0x194e79,_0x11d689[_0xbff2('0x1f')][_0xbff2('0x20')]);return _0x19dfea(_0x11d689['error'][_0xbff2('0x20')]);}else{logger[_0xbff2('0x19')](_0xbff2('0x1a'),_0x194e79,'request\x20sent');_0x19dfea(_0x11d689['result'][_0xbff2('0x20')]);}})[_0xbff2('0x21')](function(_0x2707c5){logger[_0xbff2('0x1f')](_0xbff2('0x1a'),_0x194e79,_0x2707c5);_0x293cd5(_0x2707c5);});});}function respondWithStatusCode(_0x5a9194,_0xbb3b72){_0xbb3b72=_0xbb3b72||0xcc;return function(_0x4d5019){if(_0x4d5019){return _0x5a9194[_0xbff2('0x22')](_0xbb3b72);}return _0x5a9194[_0xbff2('0x23')](_0xbb3b72)['end']();};}function respondWithResult(_0x45dc72,_0x395e65){_0x395e65=_0x395e65||0xc8;return function(_0x3954d4){if(_0x3954d4){return _0x45dc72['status'](_0x395e65)[_0xbff2('0x24')](_0x3954d4);}};}function respondWithFilteredResult(_0x3048ff,_0x18e516){return function(_0x1d02cf){if(_0x1d02cf){var _0x65c481=_0x1d02cf[_0xbff2('0x25')],_0x120ddc=_0x18e516['offset'],_0x138071=_0x18e516[_0xbff2('0x26')]+_0x18e516[_0xbff2('0x27')],_0x471d3a;if(_0x138071>=_0x65c481){_0x138071=_0x65c481;_0x471d3a=0xc8;}else{_0x471d3a=0xce;}_0x3048ff[_0xbff2('0x23')](_0x471d3a);return _0x3048ff[_0xbff2('0x28')](_0xbff2('0x29'),_0x120ddc+'-'+_0x138071+'/'+_0x65c481)['json'](_0x1d02cf);}return null;};}function patchUpdates(_0x271883){return function(_0x5604b7){try{jsonpatch[_0xbff2('0x2a')](_0x5604b7,_0x271883,!![]);}catch(_0x29912e){return BPromise[_0xbff2('0x2b')](_0x29912e);}return _0x5604b7[_0xbff2('0x2c')]();};}function saveUpdates(_0x3bf1b3,_0x3fbdfd){return function(_0x168929){if(_0x168929){return _0x168929[_0xbff2('0x2d')](_0x3bf1b3)[_0xbff2('0x2e')](function(_0x459c7e){return _0x459c7e;});}return null;};}function removeEntity(_0x48d73e,_0x3d9860){return function(_0x489ff5){if(_0x489ff5){return _0x489ff5[_0xbff2('0x2f')]()[_0xbff2('0x2e')](function(){var _0x5312cb=_0x489ff5[_0xbff2('0x30')]({'plain':!![]});var _0x171928=_0xbff2('0x31');return db['UserProfileResource'][_0xbff2('0x2f')]({'where':{'type':_0x171928,'resourceId':_0x5312cb['id']}})[_0xbff2('0x2e')](function(){return _0x489ff5;});})['then'](function(){_0x48d73e[_0xbff2('0x23')](0xcc)[_0xbff2('0x32')]();});}};}function handleEntityNotFound(_0x3db3da,_0x4d4b91){return function(_0x588b10){if(!_0x588b10){_0x3db3da[_0xbff2('0x22')](0x194);}return _0x588b10;};}function handleError(_0x3e5eb5,_0x2489c1){_0x2489c1=_0x2489c1||0x1f4;return function(_0x5edaaa){logger[_0xbff2('0x1f')](_0x5edaaa[_0xbff2('0x33')]);if(_0x5edaaa[_0xbff2('0x34')]){delete _0x5edaaa[_0xbff2('0x34')];}_0x3e5eb5[_0xbff2('0x23')](_0x2489c1)['send'](_0x5edaaa);};}exports[_0xbff2('0x35')]=function(_0x26faf6,_0x3c3581){var _0x3482ae={},_0x2d8fb5={},_0x148119={'count':0x0,'rows':[]};var _0x2718b5=_['map'](db[_0xbff2('0x36')][_0xbff2('0x37')],function(_0x30348d){return{'name':_0x30348d[_0xbff2('0x38')],'type':_0x30348d[_0xbff2('0x39')]['key']};});_0x2d8fb5[_0xbff2('0x3a')]=_['map'](_0x2718b5,_0xbff2('0x34'));_0x2d8fb5[_0xbff2('0x3b')]=_[_0xbff2('0x3c')](_0x26faf6[_0xbff2('0x3b')]);_0x2d8fb5[_0xbff2('0x3d')]=_['intersection'](_0x2d8fb5[_0xbff2('0x3a')],_0x2d8fb5[_0xbff2('0x3b')]);_0x3482ae[_0xbff2('0x3e')]=_[_0xbff2('0x3f')](_0x2d8fb5[_0xbff2('0x3a')],qs[_0xbff2('0x40')](_0x26faf6['query']['fields']));_0x3482ae[_0xbff2('0x3e')]=_0x3482ae[_0xbff2('0x3e')][_0xbff2('0x41')]?_0x3482ae[_0xbff2('0x3e')]:_0x2d8fb5[_0xbff2('0x3a')];if(!_0x26faf6['query'][_0xbff2('0x42')](_0xbff2('0x43'))){_0x3482ae[_0xbff2('0x27')]=qs[_0xbff2('0x27')](_0x26faf6[_0xbff2('0x3b')][_0xbff2('0x27')]);_0x3482ae['offset']=qs[_0xbff2('0x26')](_0x26faf6[_0xbff2('0x3b')][_0xbff2('0x26')]);}_0x3482ae[_0xbff2('0x44')]=qs[_0xbff2('0x45')](_0x26faf6[_0xbff2('0x3b')][_0xbff2('0x45')]);_0x3482ae[_0xbff2('0x46')]=qs[_0xbff2('0x3d')](_[_0xbff2('0x47')](_0x26faf6[_0xbff2('0x3b')],_0x2d8fb5[_0xbff2('0x3d')]),_0x2718b5);if(_0x26faf6[_0xbff2('0x3b')][_0xbff2('0x48')]){_0x3482ae['where']=_['merge'](_0x3482ae[_0xbff2('0x46')],{'$or':_['map'](_0x2718b5,function(_0x42d854){if(_0x42d854['type']!==_0xbff2('0x49')){var _0x12a27b={};_0x12a27b[_0x42d854[_0xbff2('0x34')]]={'$like':'%'+_0x26faf6['query'][_0xbff2('0x48')]+'%'};return _0x12a27b;}})});}_0x3482ae=_['merge']({},_0x3482ae,_0x26faf6['options']);var _0x1e8ffb={'where':_0x3482ae[_0xbff2('0x46')]};return db[_0xbff2('0x36')][_0xbff2('0x25')](_0x1e8ffb)[_0xbff2('0x2e')](function(_0x38389f){_0x148119[_0xbff2('0x25')]=_0x38389f;if(_0x26faf6['query'][_0xbff2('0x4a')]){_0x3482ae[_0xbff2('0x4b')]=[{'all':!![]}];}return db[_0xbff2('0x36')][_0xbff2('0x4c')](_0x3482ae);})[_0xbff2('0x2e')](function(_0x1afcf9){_0x148119[_0xbff2('0x4d')]=_0x1afcf9;return _0x148119;})[_0xbff2('0x2e')](respondWithFilteredResult(_0x3c3581,_0x3482ae))[_0xbff2('0x21')](handleError(_0x3c3581,null));};exports[_0xbff2('0x4e')]=function(_0x3d8efd,_0x431afb){var _0x354bb5={'raw':![],'where':{'id':_0x3d8efd['params']['id']}},_0x180e94={};_0x180e94['model']=_[_0xbff2('0x3c')](db['Trunk']['rawAttributes']);_0x180e94[_0xbff2('0x3b')]=_['keys'](_0x3d8efd[_0xbff2('0x3b')]);_0x180e94[_0xbff2('0x3d')]=_['intersection'](_0x180e94['model'],_0x180e94['query']);_0x354bb5[_0xbff2('0x3e')]=_[_0xbff2('0x3f')](_0x180e94[_0xbff2('0x3a')],qs[_0xbff2('0x40')](_0x3d8efd[_0xbff2('0x3b')][_0xbff2('0x40')]));_0x354bb5[_0xbff2('0x3e')]=_0x354bb5[_0xbff2('0x3e')][_0xbff2('0x41')]?_0x354bb5[_0xbff2('0x3e')]:_0x180e94['model'];if(_0x3d8efd[_0xbff2('0x3b')][_0xbff2('0x4a')]){_0x354bb5[_0xbff2('0x4b')]=[{'all':!![]}];}_0x354bb5=_[_0xbff2('0x4f')]({},_0x354bb5,_0x3d8efd[_0xbff2('0x50')]);return db['Trunk'][_0xbff2('0x51')](_0x354bb5)[_0xbff2('0x2e')](handleEntityNotFound(_0x431afb,null))[_0xbff2('0x2e')](respondWithResult(_0x431afb,null))[_0xbff2('0x21')](handleError(_0x431afb,null));};exports[_0xbff2('0x52')]=function(_0x1f1573,_0x149d49){var _0x4b3501={'where':{'id':_0x1f1573['params']['id']}},_0x3d4b44={};_0x3d4b44[_0xbff2('0x3a')]=_[_0xbff2('0x3c')](db[_0xbff2('0x36')]['rawAttributes']);_0x4b3501[_0xbff2('0x3e')]=_[_0xbff2('0x3f')](_0x3d4b44[_0xbff2('0x3a')],qs[_0xbff2('0x40')](_0x1f1573[_0xbff2('0x3b')][_0xbff2('0x40')]));_0x4b3501['attributes']=_0x4b3501['attributes']['length']?_0x4b3501[_0xbff2('0x3e')]:_0x3d4b44[_0xbff2('0x3a')];if(_0x1f1573[_0xbff2('0x3b')]['includeAll']){_0x4b3501['include']=[{'all':!![]}];}_0x4b3501=_['merge']({},_0x4b3501,_0x1f1573[_0xbff2('0x50')]);return db['Trunk']['find'](_0x4b3501)[_0xbff2('0x2e')](handleEntityNotFound(_0x149d49,null))[_0xbff2('0x2e')](function(_0x5109d2){if(_0x5109d2){var _0x133ae3=_0x5109d2[_0xbff2('0x30')]({'plain':!![]});_0x133ae3=qs[_0xbff2('0x53')](_0x133ae3,['id',_0xbff2('0x54'),_0xbff2('0x55')]);_0x1f1573[_0xbff2('0x56')]=_['omit'](_0x1f1573['body'],['id','createdAt',_0xbff2('0x55')]);return db[_0xbff2('0x36')][_0xbff2('0x57')](_[_0xbff2('0x4f')](_0x133ae3,_0x1f1573[_0xbff2('0x56')]),{'include':_0x1f1573[_0xbff2('0x3b')][_0xbff2('0x4a')]?[{'all':!![]}]:undefined})[_0xbff2('0x2e')](function(_0x12907f){var _0x58bcde=_0x1f1573['user'][_0xbff2('0x30')]({'plain':!![]});if(!_0x58bcde)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x58bcde[_0xbff2('0x58')]===_0xbff2('0x59')){var _0x3c3472=_0x12907f[_0xbff2('0x30')]({'plain':!![]});var _0x3e90d5='Trunks';return db[_0xbff2('0x5a')][_0xbff2('0x51')]({'where':{'name':_0x3e90d5,'userProfileId':_0x58bcde[_0xbff2('0x5b')]},'raw':!![]})[_0xbff2('0x2e')](function(_0x264e12){if(_0x264e12&&_0x264e12['autoAssociation']===0x0){return db['UserProfileResource'][_0xbff2('0x57')]({'name':_0x3c3472[_0xbff2('0x34')],'resourceId':_0x3c3472['id'],'type':_0x264e12[_0xbff2('0x34')],'sectionId':_0x264e12['id']},{})[_0xbff2('0x2e')](function(){return _0x12907f;});}else{return _0x12907f;}})['catch'](function(_0x594e07){logger[_0xbff2('0x1f')](_0xbff2('0x5c'),_0x594e07);throw _0x594e07;});}return _0x12907f;});}})[_0xbff2('0x2e')](respondWithResult(_0x149d49,0xc9))[_0xbff2('0x21')](handleError(_0x149d49,null));};exports[_0xbff2('0x57')]=function(_0x2af76e,_0x4de19e,_0x119108){var _0x13d217;return db['Trunk'][_0xbff2('0x57')](_0x2af76e[_0xbff2('0x56')],{'raw':!![]})[_0xbff2('0x2e')](function(_0x42129d){_0x13d217=_0x42129d;return db[_0xbff2('0x36')]['findAll']({'raw':!![]});})[_0xbff2('0x2e')](function(_0x3860be){var _0xf3f450=fs[_0xbff2('0x5d')](path['join'](config[_0xbff2('0x5e')],_0xbff2('0x5f')),'utf8');var _0x4ae37c=fs[_0xbff2('0x5d')](path['join'](config[_0xbff2('0x5e')],_0xbff2('0x60')),_0xbff2('0x61'));var _0x203f5a=ejs[_0xbff2('0x62')](_0xf3f450,{'trunks':_0x3860be||[]});fs[_0xbff2('0x63')](_0xbff2('0x64'),_0x203f5a);if(_0x13d217[_0xbff2('0x65')]){var _0x27e08f=ejs[_0xbff2('0x62')](_0x4ae37c,{'trunks':_0x3860be||[]});fs['writeFileSync'](_0xbff2('0x66'),_0x27e08f);}})[_0xbff2('0x2e')](function(){return respondWithRpcPromise(_0xbff2('0x67'),_0xbff2('0x57'),{'module':_0xbff2('0x68')});})[_0xbff2('0x2e')](function(){var _0x296fd8=_0x2af76e[_0xbff2('0x59')][_0xbff2('0x30')]({'plain':!![]});if(!_0x296fd8)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x296fd8[_0xbff2('0x58')]===_0xbff2('0x59')){var _0xb3d272=_0x13d217[_0xbff2('0x30')]({'plain':!![]});return db[_0xbff2('0x5a')][_0xbff2('0x51')]({'where':{'name':'Trunks','userProfileId':_0x296fd8[_0xbff2('0x5b')]},'raw':!![]})[_0xbff2('0x2e')](function(_0x5c1f18){if(_0x5c1f18&&_0x5c1f18[_0xbff2('0x69')]===0x0){return db['UserProfileResource'][_0xbff2('0x57')]({'name':_0xb3d272['name'],'resourceId':_0xb3d272['id'],'type':_0x5c1f18[_0xbff2('0x34')],'sectionId':_0x5c1f18['id']},{})['then'](function(){return _0x13d217;});}else{return _0x13d217;}})[_0xbff2('0x21')](function(_0x5bb5c0){logger[_0xbff2('0x1f')](_0xbff2('0x5c'),_0x5bb5c0);throw _0x5bb5c0;});}return _0x13d217;})[_0xbff2('0x2e')](respondWithResult(_0x4de19e,0xc9))[_0xbff2('0x21')](handleError(_0x4de19e,null));};exports[_0xbff2('0x2d')]=function(_0x383a7,_0x2d8927,_0x144f2d){var _0x1680f2;return db['Trunk']['find']({'where':{'id':_0x383a7['params']['id']}})['then'](handleEntityNotFound(_0x2d8927,null))[_0xbff2('0x2e')](saveUpdates(_0x383a7[_0xbff2('0x56')],null))[_0xbff2('0x2e')](function(_0x1daacd){if(_0x1daacd){_0x1680f2=_0x1daacd;return db[_0xbff2('0x36')]['findAll']({'raw':!![]});}})[_0xbff2('0x2e')](function(_0x27a743){if(_0x27a743){var _0x1268aa=fs[_0xbff2('0x5d')](path[_0xbff2('0x6a')](config['root'],'server/files/templates/trunk.ejs'),_0xbff2('0x61'));var _0xccd026=fs[_0xbff2('0x5d')](path['join'](config[_0xbff2('0x5e')],_0xbff2('0x60')),_0xbff2('0x61'));var _0xdb35c4=ejs[_0xbff2('0x62')](_0x1268aa,{'trunks':_0x27a743||[]});fs[_0xbff2('0x63')]('/etc/asterisk/sip_xcally_trunks.conf',_0xdb35c4);var _0x289737=ejs[_0xbff2('0x62')](_0xccd026,{'trunks':_0x27a743||[]});fs[_0xbff2('0x63')](_0xbff2('0x66'),_0x289737);return respondWithRpcPromise(_0xbff2('0x67'),_0xbff2('0x2d'),{'module':_0xbff2('0x68')});}return null;})[_0xbff2('0x2e')](function(_0x17a1ef){if(_0x17a1ef){return _0x1680f2;}})['then'](respondWithResult(_0x2d8927,null))['catch'](handleError(_0x2d8927,null));};exports[_0xbff2('0x2f')]=function(_0x3e1bab,_0x28697c,_0x7c9f50){var _0x121455;return db[_0xbff2('0x36')][_0xbff2('0x51')]({'where':{'id':_0x3e1bab['params']['id']}})[_0xbff2('0x2e')](handleEntityNotFound(_0x28697c,null))['then'](removeEntity(_0x28697c,null))[_0xbff2('0x2e')](function(){return db[_0xbff2('0x36')][_0xbff2('0x4c')]({'raw':!![]});})[_0xbff2('0x2e')](function(_0x373fc4){var _0xb58276=fs[_0xbff2('0x5d')](path[_0xbff2('0x6a')](config[_0xbff2('0x5e')],_0xbff2('0x5f')),_0xbff2('0x61'));var _0x3aa6c1=fs[_0xbff2('0x5d')](path[_0xbff2('0x6a')](config[_0xbff2('0x5e')],'server/files/templates/registry.ejs'),_0xbff2('0x61'));var _0x2bf1c6=ejs[_0xbff2('0x62')](_0xb58276,{'trunks':_0x373fc4});var _0x523ce6=ejs['render'](_0x3aa6c1,{'trunks':_0x373fc4});fs[_0xbff2('0x63')]('/etc/asterisk/sip_xcally_trunks.conf',_0x2bf1c6);fs[_0xbff2('0x63')](_0xbff2('0x66'),_0x523ce6);return respondWithRpcPromise('Reload','destroy',{'module':_0xbff2('0x68')});})[_0xbff2('0x21')](handleError(_0x28697c,null));};
\ No newline at end of file