Built motion from commit 129fb4d95212661e48f0db455e75d668addbaddf. Version 3.0.0...
[motion-next.git] / server / api / trunk / trunk.controller.js
index 69559bd..df29a32 100644 (file)
@@ -1 +1 @@
-const a643_0x4a51=['update','set','key','createdAt','lodash','VIRTUAL','order','sequelize','filter','UserProfileResource','Trunk','join','/etc/asterisk/sip_xcally_registers.conf','chan_sip.so','nolimit','destroy','merge','stack','omit','count','role','result','keys','Content-Range','render','files/templates/trunk.ejs','../../components/parsers/qs','info','request\x20sent','files/templates/registry.ejs','where','autoAssociation','length','filters','clone','json','Unable\x20to\x20retrieve\x20the\x20current\x20user','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','/etc/asterisk/sip_xcally_trunks.conf','body','rawAttributes','Trunk,\x20%s,\x20%s','http','catch','registry','pick','end','user','model','get','create','sendStatus','include','intersection','fieldName','includeAll','readFileSync','attributes','request','name','root','error','params','code','type','show','send','message','UserProfileSection','userProfileId','Trunks','sort','findOne','then','limit','index','query','api','map','updatedAt','fields','client','utf8','findAll','../../config/logger','status','options','writeFileSync','jayson/promise','offset','Reload'];(function(_0x52234e,_0x4a51e8){const _0x2b477f=function(_0x130079){while(--_0x130079){_0x52234e['push'](_0x52234e['shift']());}};_0x2b477f(++_0x4a51e8);}(a643_0x4a51,0x1e4));const a643_0x2b47=function(_0x52234e,_0x4a51e8){_0x52234e=_0x52234e-0x0;let _0x2b477f=a643_0x4a51[_0x52234e];return _0x2b477f;};const _0x5939dd=a643_0x2b47;'use strict';const path=require('path'),ejs=require('ejs'),fs=require('fs'),_=require(_0x5939dd('0x42')),qs=require(_0x5939dd('0x58')),logger=require(_0x5939dd('0x37'))(_0x5939dd('0x30')),config=require('../../config/environment'),db=require('../../mysqldb')['db'],{Op}=require(_0x5939dd('0x45')),jayson=require(_0x5939dd('0x3b')),client=jayson[_0x5939dd('0x34')][_0x5939dd('0xd')]({'port':0x232a});function respondWithRpcPromise(_0x130079,_0x570007,_0x4a4773,_0x5c08f1){return new Promise(function(_0x4ab911,_0x5094a2){const _0x4c4591=a643_0x2b47,_0x2e4081=_0x5c08f1||client;return _0x2e4081[_0x4c4591('0x1d')](_0x130079,_0x4a4773)[_0x4c4591('0x2c')](function(_0x569153){const _0x58a384=_0x4c4591;logger[_0x58a384('0x59')](_0x58a384('0xc'),_0x570007,_0x58a384('0x5a')),logger['debug']('Trunk,\x20%s,\x20%s,\x20%s',_0x570007,_0x58a384('0x5a'),JSON['stringify'](_0x569153));if(_0x569153[_0x58a384('0x20')]){if(_0x569153[_0x58a384('0x20')][_0x58a384('0x22')]===0x1f4)return logger[_0x58a384('0x20')](_0x58a384('0xc'),_0x570007,_0x569153[_0x58a384('0x20')][_0x58a384('0x26')]),_0x5094a2(_0x569153[_0x58a384('0x20')][_0x58a384('0x26')]);return logger[_0x58a384('0x20')](_0x58a384('0xc'),_0x570007,_0x569153[_0x58a384('0x20')][_0x58a384('0x26')]),_0x4ab911(_0x569153[_0x58a384('0x20')]['message']);}else logger[_0x58a384('0x59')](_0x58a384('0xc'),_0x570007,'request\x20sent'),_0x4ab911(_0x569153[_0x58a384('0x53')][_0x58a384('0x26')]);})['catch'](function(_0x1f68a9){const _0x5d6507=_0x4c4591;logger[_0x5d6507('0x20')]('Trunk,\x20%s,\x20%s',_0x570007,_0x1f68a9),_0x5094a2(_0x1f68a9);});});}function respondWithResult(_0x1d6517,_0x55062d){return _0x55062d=_0x55062d||0xc8,function(_0x268a0b){const _0x329a65=a643_0x2b47;if(_0x268a0b)return _0x1d6517[_0x329a65('0x38')](_0x55062d)['json'](_0x268a0b);};}function respondWithFilteredResult(_0x2f5283,_0x3ec915){return function(_0x1a99f9){const _0x3332a7=a643_0x2b47;if(_0x1a99f9){const _0x3fb2cb=_0x1a99f9[_0x3332a7('0x51')],_0x15b893=_0x3ec915['offset'];let _0x4f923a=_0x3ec915[_0x3332a7('0x3c')]+_0x3ec915[_0x3332a7('0x2d')],_0xe44b78;return _0x4f923a>=_0x3fb2cb?(_0x4f923a=_0x3fb2cb,_0xe44b78=0xc8):_0xe44b78=0xce,_0x2f5283[_0x3332a7('0x38')](_0xe44b78),_0x2f5283[_0x3332a7('0x3f')](_0x3332a7('0x55'),_0x15b893+'-'+_0x4f923a+'/'+_0x3fb2cb)[_0x3332a7('0x6')](_0x1a99f9);}return null;};}function saveUpdates(_0x41bd12){return function(_0x44450a){const _0x379a7e=a643_0x2b47;if(_0x44450a)return _0x44450a[_0x379a7e('0x3e')](_0x41bd12)[_0x379a7e('0x2c')](function(_0x38fc3a){return _0x38fc3a;});return null;};}function removeEntity(_0x464f49){return function(_0x50908a){const _0x344a8d=a643_0x2b47;if(_0x50908a)return _0x50908a['destroy']()[_0x344a8d('0x2c')](function(){const _0x54fff4=_0x344a8d,_0x294939=_0x50908a['get']({'plain':!![]}),_0x48953b=_0x54fff4('0x29');return db[_0x54fff4('0x47')]['destroy']({'where':{'type':_0x48953b,'resourceId':_0x294939['id']}})[_0x54fff4('0x2c')](function(){return _0x50908a;});})['then'](function(){const _0x351164=_0x344a8d;_0x464f49[_0x351164('0x38')](0xcc)[_0x351164('0x11')]();});};}function handleEntityNotFound(_0x4ca906){return function(_0xd836d3){const _0x4f9a12=a643_0x2b47;return!_0xd836d3&&_0x4ca906[_0x4f9a12('0x16')](0x194),_0xd836d3;};}function handleError(_0x585426,_0x2f42cd){return _0x2f42cd=_0x2f42cd||0x1f4,function(_0x11e453){const _0x5ef470=a643_0x2b47;logger[_0x5ef470('0x20')](_0x11e453[_0x5ef470('0x4f')]),_0x11e453['name']&&delete _0x11e453[_0x5ef470('0x1e')],_0x585426[_0x5ef470('0x38')](_0x2f42cd)[_0x5ef470('0x25')](_0x11e453);};}exports[_0x5939dd('0x2e')]=function(_0x2f6365,_0x5c5879){const _0x446529=_0x5939dd;let _0x1a5078={};const _0x46ff24={},_0x585b06={'count':0x0,'rows':[]},_0x4f8f0c=_['map'](db[_0x446529('0x48')]['rawAttributes'],function(_0x483e3){const _0x3848ba=_0x446529;return{'name':_0x483e3[_0x3848ba('0x19')],'type':_0x483e3[_0x3848ba('0x23')][_0x3848ba('0x40')]};});_0x46ff24['model']=_[_0x446529('0x31')](_0x4f8f0c,_0x446529('0x1e')),_0x46ff24['query']=_[_0x446529('0x54')](_0x2f6365[_0x446529('0x2f')]),_0x46ff24[_0x446529('0x4')]=_[_0x446529('0x18')](_0x46ff24[_0x446529('0x13')],_0x46ff24[_0x446529('0x2f')]),_0x1a5078[_0x446529('0x1c')]=_[_0x446529('0x18')](_0x46ff24[_0x446529('0x13')],qs['fields'](_0x2f6365[_0x446529('0x2f')][_0x446529('0x33')])),_0x1a5078[_0x446529('0x1c')]=_0x1a5078[_0x446529('0x1c')][_0x446529('0x3')]?_0x1a5078[_0x446529('0x1c')]:_0x46ff24[_0x446529('0x13')];typeof _0x2f6365[_0x446529('0x2f')][_0x446529('0x4c')]==='undefined'&&(_0x1a5078[_0x446529('0x2d')]=qs[_0x446529('0x2d')](_0x2f6365[_0x446529('0x2f')][_0x446529('0x2d')]),_0x1a5078[_0x446529('0x3c')]=qs[_0x446529('0x3c')](_0x2f6365[_0x446529('0x2f')][_0x446529('0x3c')]));_0x1a5078[_0x446529('0x44')]=qs[_0x446529('0x2a')](_0x2f6365[_0x446529('0x2f')][_0x446529('0x2a')]),_0x1a5078[_0x446529('0x1')]=qs[_0x446529('0x4')](_[_0x446529('0x10')](_0x2f6365[_0x446529('0x2f')],_0x46ff24[_0x446529('0x4')]),_0x4f8f0c);_0x2f6365[_0x446529('0x2f')]['filter']&&(_0x1a5078['where']=_['merge'](_0x1a5078[_0x446529('0x1')],{[Op['or']]:_[_0x446529('0x31')](_0x4f8f0c,function(_0x125d92){const _0x3ff1ae=_0x446529;if(_0x125d92[_0x3ff1ae('0x23')]!==_0x3ff1ae('0x43')){const _0x550855={};return _0x550855[_0x125d92[_0x3ff1ae('0x1e')]]={[Op['like']]:'%'+_0x2f6365['query'][_0x3ff1ae('0x46')]+'%'},_0x550855;}})}));_0x1a5078=_[_0x446529('0x4e')]({},_0x1a5078,_0x2f6365[_0x446529('0x39')]);const _0x131bc2={'where':_0x1a5078[_0x446529('0x1')]};return db['Trunk'][_0x446529('0x51')](_0x131bc2)[_0x446529('0x2c')](function(_0x29acf8){const _0x3521fe=_0x446529;return _0x585b06[_0x3521fe('0x51')]=_0x29acf8,_0x2f6365[_0x3521fe('0x2f')][_0x3521fe('0x1a')]&&(_0x1a5078[_0x3521fe('0x17')]=[{'all':!![]}]),db[_0x3521fe('0x48')][_0x3521fe('0x36')](_0x1a5078);})[_0x446529('0x2c')](function(_0x1545f3){return _0x585b06['rows']=_0x1545f3,_0x585b06;})['then'](respondWithFilteredResult(_0x5c5879,_0x1a5078))['catch'](handleError(_0x5c5879,null));},exports[_0x5939dd('0x24')]=function(_0x4a84ab,_0x47cec1){const _0x4769f6=_0x5939dd;let _0x503e83={'raw':![],'where':{'id':_0x4a84ab[_0x4769f6('0x21')]['id']}};const _0x1854fb={};return _0x1854fb[_0x4769f6('0x13')]=_[_0x4769f6('0x54')](db[_0x4769f6('0x48')][_0x4769f6('0xb')]),_0x1854fb[_0x4769f6('0x2f')]=_[_0x4769f6('0x54')](_0x4a84ab[_0x4769f6('0x2f')]),_0x1854fb[_0x4769f6('0x4')]=_[_0x4769f6('0x18')](_0x1854fb[_0x4769f6('0x13')],_0x1854fb[_0x4769f6('0x2f')]),_0x503e83['attributes']=_[_0x4769f6('0x18')](_0x1854fb['model'],qs[_0x4769f6('0x33')](_0x4a84ab[_0x4769f6('0x2f')]['fields'])),_0x503e83[_0x4769f6('0x1c')]=_0x503e83['attributes'][_0x4769f6('0x3')]?_0x503e83['attributes']:_0x1854fb[_0x4769f6('0x13')],_0x4a84ab[_0x4769f6('0x2f')][_0x4769f6('0x1a')]&&(_0x503e83[_0x4769f6('0x17')]=[{'all':!![]}]),_0x503e83=_[_0x4769f6('0x4e')]({},_0x503e83,_0x4a84ab['options']),db['Trunk'][_0x4769f6('0x2b')](_0x503e83)[_0x4769f6('0x2c')](handleEntityNotFound(_0x47cec1,null))[_0x4769f6('0x2c')](respondWithResult(_0x47cec1,null))[_0x4769f6('0xe')](handleError(_0x47cec1,null));},exports[_0x5939dd('0x5')]=function(_0x284b37,_0x1a5930){const _0x4dea30=_0x5939dd;let _0x4e9c30={'where':{'id':_0x284b37[_0x4dea30('0x21')]['id']}};const _0x2565ab={};return _0x2565ab[_0x4dea30('0x13')]=_[_0x4dea30('0x54')](db[_0x4dea30('0x48')][_0x4dea30('0xb')]),_0x4e9c30['attributes']=_[_0x4dea30('0x18')](_0x2565ab[_0x4dea30('0x13')],qs[_0x4dea30('0x33')](_0x284b37[_0x4dea30('0x2f')][_0x4dea30('0x33')])),_0x4e9c30[_0x4dea30('0x1c')]=_0x4e9c30[_0x4dea30('0x1c')][_0x4dea30('0x3')]?_0x4e9c30['attributes']:_0x2565ab[_0x4dea30('0x13')],_0x284b37[_0x4dea30('0x2f')]['includeAll']&&(_0x4e9c30[_0x4dea30('0x17')]=[{'all':!![]}]),_0x4e9c30=_[_0x4dea30('0x4e')]({},_0x4e9c30,_0x284b37[_0x4dea30('0x39')]),db['Trunk'][_0x4dea30('0x2b')](_0x4e9c30)['then'](handleEntityNotFound(_0x1a5930,null))[_0x4dea30('0x2c')](function(_0xb70b5c){const _0x224224=_0x4dea30;if(_0xb70b5c){let _0x44c6c8=_0xb70b5c['get']({'plain':!![]});return _0x44c6c8=qs['omit'](_0x44c6c8,['id','createdAt',_0x224224('0x32')]),_0x284b37[_0x224224('0xa')]=_[_0x224224('0x50')](_0x284b37[_0x224224('0xa')],['id',_0x224224('0x41'),'updatedAt']),db[_0x224224('0x48')][_0x224224('0x15')](_['merge'](_0x44c6c8,_0x284b37[_0x224224('0xa')]),{'include':_0x284b37['query'][_0x224224('0x1a')]?[{'all':!![]}]:undefined})[_0x224224('0x2c')](function(_0x3857fc){const _0x2b389e=_0x224224,_0x4a0685=_0x284b37[_0x2b389e('0x12')]['get']({'plain':!![]});if(!_0x4a0685)throw new Error(_0x2b389e('0x7'));if(_0x4a0685[_0x2b389e('0x52')]===_0x2b389e('0x12')){const _0x382c01=_0x3857fc[_0x2b389e('0x14')]({'plain':!![]}),_0x1a31d0=_0x2b389e('0x29');return db[_0x2b389e('0x27')][_0x2b389e('0x2b')]({'where':{'name':_0x1a31d0,'userProfileId':_0x4a0685[_0x2b389e('0x28')]},'raw':!![]})[_0x2b389e('0x2c')](function(_0x87a436){const _0x2dfd2e=_0x2b389e;return _0x87a436&&_0x87a436[_0x2dfd2e('0x2')]===0x0?db['UserProfileResource'][_0x2dfd2e('0x15')]({'name':_0x382c01[_0x2dfd2e('0x1e')],'resourceId':_0x382c01['id'],'type':_0x87a436['name'],'sectionId':_0x87a436['id']},{})['then'](function(){return _0x3857fc;}):_0x3857fc;})[_0x2b389e('0xe')](function(_0x2b46ee){const _0x3a50de=_0x2b389e;logger[_0x3a50de('0x20')](_0x3a50de('0x8'),_0x2b46ee);throw _0x2b46ee;});}return _0x3857fc;});}})[_0x4dea30('0x2c')](respondWithResult(_0x1a5930,0xc9))[_0x4dea30('0xe')](handleError(_0x1a5930,null));},exports[_0x5939dd('0x15')]=function(_0x2385bb,_0x38fb2f){const _0x326bb9=_0x5939dd;let _0x3eb722;return db[_0x326bb9('0x48')][_0x326bb9('0x15')](_0x2385bb[_0x326bb9('0xa')],{'raw':!![]})[_0x326bb9('0x2c')](function(_0x2211f7){const _0x33ed22=_0x326bb9;return _0x3eb722=_0x2211f7,db[_0x33ed22('0x48')][_0x33ed22('0x36')]({'raw':!![]});})['then'](function(_0x4bd1c0){const _0x4a5a5c=_0x326bb9,_0xba81cb=fs[_0x4a5a5c('0x1b')](path[_0x4a5a5c('0x49')](config[_0x4a5a5c('0x1f')],_0x4a5a5c('0x57')),_0x4a5a5c('0x35')),_0x5c103a=fs[_0x4a5a5c('0x1b')](path[_0x4a5a5c('0x49')](config[_0x4a5a5c('0x1f')],_0x4a5a5c('0x0')),'utf8'),_0x35561a=ejs[_0x4a5a5c('0x56')](_0xba81cb,{'trunks':_0x4bd1c0||[]});fs[_0x4a5a5c('0x3a')]('/etc/asterisk/sip_xcally_trunks.conf',_0x35561a);if(_0x3eb722[_0x4a5a5c('0xf')]){const _0x2a6372=ejs[_0x4a5a5c('0x56')](_0x5c103a,{'trunks':_0x4bd1c0||[]});fs[_0x4a5a5c('0x3a')]('/etc/asterisk/sip_xcally_registers.conf',_0x2a6372);}})['then'](function(){const _0x14a2e4=_0x326bb9;return respondWithRpcPromise(_0x14a2e4('0x3d'),_0x14a2e4('0x15'),{'module':_0x14a2e4('0x4b')});})[_0x326bb9('0x2c')](function(){const _0x1d0c5f=_0x326bb9,_0x2acb39=_0x2385bb[_0x1d0c5f('0x12')][_0x1d0c5f('0x14')]({'plain':!![]});if(!_0x2acb39)throw new Error(_0x1d0c5f('0x7'));if(_0x2acb39[_0x1d0c5f('0x52')]===_0x1d0c5f('0x12')){const _0x1742f7=_0x3eb722[_0x1d0c5f('0x14')]({'plain':!![]});return db[_0x1d0c5f('0x27')]['findOne']({'where':{'name':_0x1d0c5f('0x29'),'userProfileId':_0x2acb39[_0x1d0c5f('0x28')]},'raw':!![]})['then'](function(_0xb26141){const _0x12baf2=_0x1d0c5f;return _0xb26141&&_0xb26141['autoAssociation']===0x0?db[_0x12baf2('0x47')]['create']({'name':_0x1742f7[_0x12baf2('0x1e')],'resourceId':_0x1742f7['id'],'type':_0xb26141[_0x12baf2('0x1e')],'sectionId':_0xb26141['id']},{})[_0x12baf2('0x2c')](function(){return _0x3eb722;}):_0x3eb722;})[_0x1d0c5f('0xe')](function(_0x28d5cb){const _0x690d52=_0x1d0c5f;logger['error'](_0x690d52('0x8'),_0x28d5cb);throw _0x28d5cb;});}return _0x3eb722;})[_0x326bb9('0x2c')](respondWithResult(_0x38fb2f,0xc9))['catch'](handleError(_0x38fb2f,null));},exports[_0x5939dd('0x3e')]=function(_0x16bc93,_0x44ab67){const _0x2996a6=_0x5939dd;let _0x160f03;return db[_0x2996a6('0x48')][_0x2996a6('0x2b')]({'where':{'id':_0x16bc93['params']['id']}})[_0x2996a6('0x2c')](handleEntityNotFound(_0x44ab67,null))[_0x2996a6('0x2c')](saveUpdates(_0x16bc93[_0x2996a6('0xa')],null))[_0x2996a6('0x2c')](function(_0x5b0791){const _0x209d62=_0x2996a6;if(_0x5b0791)return _0x160f03=_0x5b0791,db[_0x209d62('0x48')][_0x209d62('0x36')]({'raw':!![]});})[_0x2996a6('0x2c')](function(_0x16f32a){const _0x2cf252=_0x2996a6;if(_0x16f32a){const _0x2e5e2d=fs['readFileSync'](path[_0x2cf252('0x49')](config[_0x2cf252('0x1f')],_0x2cf252('0x57')),_0x2cf252('0x35')),_0x8bd666=fs[_0x2cf252('0x1b')](path[_0x2cf252('0x49')](config['root'],'files/templates/registry.ejs'),_0x2cf252('0x35')),_0x2dd57c=ejs[_0x2cf252('0x56')](_0x2e5e2d,{'trunks':_0x16f32a||[]});fs['writeFileSync'](_0x2cf252('0x9'),_0x2dd57c);const _0x5da0d9=ejs['render'](_0x8bd666,{'trunks':_0x16f32a||[]});return fs[_0x2cf252('0x3a')](_0x2cf252('0x4a'),_0x5da0d9),respondWithRpcPromise(_0x2cf252('0x3d'),_0x2cf252('0x3e'),{'module':_0x2cf252('0x4b')});}return null;})[_0x2996a6('0x2c')](function(_0x36fa7e){if(_0x36fa7e)return _0x160f03;})[_0x2996a6('0x2c')](respondWithResult(_0x44ab67,null))[_0x2996a6('0xe')](handleError(_0x44ab67,null));},exports['destroy']=function(_0x2cfd8c,_0x5f391e){const _0x517f49=_0x5939dd;return db[_0x517f49('0x48')][_0x517f49('0x2b')]({'where':{'id':_0x2cfd8c['params']['id']}})[_0x517f49('0x2c')](handleEntityNotFound(_0x5f391e,null))[_0x517f49('0x2c')](removeEntity(_0x5f391e,null))[_0x517f49('0x2c')](function(){const _0x544590=_0x517f49;return db[_0x544590('0x48')][_0x544590('0x36')]({'raw':!![]});})['then'](function(_0x1f7faa){const _0x47da96=_0x517f49,_0x3f9257=fs[_0x47da96('0x1b')](path[_0x47da96('0x49')](config['root'],_0x47da96('0x57')),_0x47da96('0x35')),_0x1d7161=fs[_0x47da96('0x1b')](path['join'](config[_0x47da96('0x1f')],'files/templates/registry.ejs'),'utf8'),_0x530c52=ejs['render'](_0x3f9257,{'trunks':_0x1f7faa}),_0x53cde7=ejs[_0x47da96('0x56')](_0x1d7161,{'trunks':_0x1f7faa});return fs[_0x47da96('0x3a')](_0x47da96('0x9'),_0x530c52),fs[_0x47da96('0x3a')](_0x47da96('0x4a'),_0x53cde7),respondWithRpcPromise('Reload',_0x47da96('0x4d'),{'module':'chan_sip.so'});})[_0x517f49('0xe')](handleError(_0x5f391e,null));};
\ No newline at end of file
+const a769_0x29c6=['sendStatus','set','join','render','userProfileId','stringify','filter','destroy','UserProfileResource','registry','then','request','order','../../components/parsers/qs','include','intersection','Trunk,\x20%s,\x20%s,\x20%s','Content-Range','body','fields','UserProfileSection','type','../../config/logger','update','/etc/asterisk/sip_xcally_registers.conf','count','files/templates/trunk.ejs','end','findAll','code','role','filters','map','options','status','offset','message','length','autoAssociation','findOne','readFileSync','model','catch','jayson/promise','sort','clone','chan_sip.so','Reload','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','files/templates/registry.ejs','utf8','request\x20sent','stack','info','../../mysqldb','limit','Unable\x20to\x20retrieve\x20the\x20current\x20user','rawAttributes','fieldName','keys','Trunks','ejs','attributes','createdAt','show','VIRTUAL','user','updatedAt','Trunk','writeFileSync','includeAll','rows','get','create','send','name','../../config/environment','error','like','merge','nolimit','/etc/asterisk/sip_xcally_trunks.conf','query','params','sequelize','undefined','json','pick','root','omit','where','Trunk,\x20%s,\x20%s'];(function(_0x35a9b2,_0x239325){const _0x29c6f8=function(_0x2f4c4c){while(--_0x2f4c4c){_0x35a9b2['push'](_0x35a9b2['shift']());}};_0x29c6f8(++_0x239325);}(a769_0x29c6,0x13b));const a769_0x2f4c=function(_0x35a9b2,_0x239325){_0x35a9b2=_0x35a9b2-0x1b7;let _0x29c6f8=a769_0x29c6[_0x35a9b2];return _0x29c6f8;};const a769_0x5b804b=a769_0x2f4c;'use strict';const path=require('path'),ejs=require(a769_0x5b804b(0x1cd)),fs=require('fs'),_=require('lodash'),qs=require(a769_0x5b804b(0x1f9)),logger=require(a769_0x5b804b(0x202))('api'),config=require(a769_0x5b804b(0x1dc)),{db}=require(a769_0x5b804b(0x1c6)),{Op}=require(a769_0x5b804b(0x1e4)),jayson=require(a769_0x5b804b(0x1bb)),client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x1341cd,_0x4e2434,_0x1cf9a1,_0x551f23){return new Promise(function(_0x4ebb31,_0x50d497){const _0x5c0644=a769_0x2f4c,_0x363db5=_0x551f23||client;return _0x363db5[_0x5c0644(0x1f7)](_0x1341cd,_0x1cf9a1)['then'](function(_0x29847c){const _0x5bf097=_0x5c0644;logger[_0x5bf097(0x1c5)]('Trunk,\x20%s,\x20%s',_0x4e2434,_0x5bf097(0x1c3)),logger['debug'](_0x5bf097(0x1fc),_0x4e2434,_0x5bf097(0x1c3),JSON[_0x5bf097(0x1f1)](_0x29847c));if(_0x29847c['error']){if(_0x29847c[_0x5bf097(0x1dd)][_0x5bf097(0x209)]===0x1f4)return logger[_0x5bf097(0x1dd)](_0x5bf097(0x1eb),_0x4e2434,_0x29847c['error'][_0x5bf097(0x210)]),_0x50d497(_0x29847c[_0x5bf097(0x1dd)][_0x5bf097(0x210)]);return logger[_0x5bf097(0x1dd)](_0x5bf097(0x1eb),_0x4e2434,_0x29847c[_0x5bf097(0x1dd)][_0x5bf097(0x210)]),_0x4ebb31(_0x29847c[_0x5bf097(0x1dd)]['message']);}else logger[_0x5bf097(0x1c5)]('Trunk,\x20%s,\x20%s',_0x4e2434,_0x5bf097(0x1c3)),_0x4ebb31(_0x29847c['result'][_0x5bf097(0x210)]);})[_0x5c0644(0x1ba)](function(_0x22779c){const _0x1cd051=_0x5c0644;logger[_0x1cd051(0x1dd)](_0x1cd051(0x1eb),_0x4e2434,_0x22779c),_0x50d497(_0x22779c);});});}function respondWithResult(_0x3ea357,_0x55e3ae){return _0x55e3ae=_0x55e3ae||0xc8,function(_0x16a384){const _0x2157a3=a769_0x2f4c;if(_0x16a384)return _0x3ea357[_0x2157a3(0x20e)](_0x55e3ae)['json'](_0x16a384);};}function respondWithFilteredResult(_0x4aa8b7,_0x5712e8){return function(_0x31a84a){const _0x3d2b70=a769_0x2f4c;if(_0x31a84a){const _0x3d198a=_0x31a84a[_0x3d2b70(0x205)],_0x46e438=_0x5712e8['offset'];let _0x23e6ab=_0x5712e8[_0x3d2b70(0x20f)]+_0x5712e8[_0x3d2b70(0x1c7)],_0x4e22e7;return _0x23e6ab>=_0x3d198a?(_0x23e6ab=_0x3d198a,_0x4e22e7=0xc8):_0x4e22e7=0xce,_0x4aa8b7[_0x3d2b70(0x20e)](_0x4e22e7),_0x4aa8b7[_0x3d2b70(0x1ed)](_0x3d2b70(0x1fd),_0x46e438+'-'+_0x23e6ab+'/'+_0x3d198a)[_0x3d2b70(0x1e6)](_0x31a84a);}return null;};}function saveUpdates(_0x50df3b){return function(_0x126a40){const _0x26cbb2=a769_0x2f4c;if(_0x126a40)return _0x126a40[_0x26cbb2(0x203)](_0x50df3b)[_0x26cbb2(0x1f6)](function(_0x42c315){return _0x42c315;});return null;};}function removeEntity(_0x105965){return function(_0x213411){const _0x4273bd=a769_0x2f4c;if(_0x213411)return _0x213411[_0x4273bd(0x1f3)]()[_0x4273bd(0x1f6)](function(){const _0x1a2aaa=_0x4273bd,_0x1d903a=_0x213411[_0x1a2aaa(0x1d8)]({'plain':!![]}),_0x13a33e=_0x1a2aaa(0x1cc);return db[_0x1a2aaa(0x1f4)][_0x1a2aaa(0x1f3)]({'where':{'type':_0x13a33e,'resourceId':_0x1d903a['id']}})[_0x1a2aaa(0x1f6)](function(){return _0x213411;});})[_0x4273bd(0x1f6)](function(){const _0x55d6e7=_0x4273bd;_0x105965[_0x55d6e7(0x20e)](0xcc)[_0x55d6e7(0x207)]();});};}function handleEntityNotFound(_0xb85abe){return function(_0x48d4ae){const _0x3a31c7=a769_0x2f4c;return!_0x48d4ae&&_0xb85abe[_0x3a31c7(0x1ec)](0x194),_0x48d4ae;};}function handleError(_0x558a70,_0x5ebb4e){return _0x5ebb4e=_0x5ebb4e||0x1f4,function(_0x52fd3f){const _0x56464f=a769_0x2f4c;logger['error'](_0x52fd3f[_0x56464f(0x1c4)]),_0x52fd3f[_0x56464f(0x1db)]&&delete _0x52fd3f[_0x56464f(0x1db)],_0x558a70[_0x56464f(0x20e)](_0x5ebb4e)[_0x56464f(0x1da)](_0x52fd3f);};}exports['index']=function(_0x5c8d14,_0x4a5f4b){const _0x6080e=a769_0x5b804b;let _0x57c0fe={};const _0x5df355={},_0x1913f7={'count':0x0,'rows':[]},_0x503c17=_[_0x6080e(0x20c)](db['Trunk'][_0x6080e(0x1c9)],function(_0x1d15a1){const _0x408e2a=_0x6080e;return{'name':_0x1d15a1[_0x408e2a(0x1ca)],'type':_0x1d15a1[_0x408e2a(0x201)]['key']};});_0x5df355[_0x6080e(0x1b9)]=_[_0x6080e(0x20c)](_0x503c17,_0x6080e(0x1db)),_0x5df355[_0x6080e(0x1e2)]=_[_0x6080e(0x1cb)](_0x5c8d14['query']),_0x5df355[_0x6080e(0x20b)]=_[_0x6080e(0x1fb)](_0x5df355[_0x6080e(0x1b9)],_0x5df355['query']),_0x57c0fe[_0x6080e(0x1ce)]=_[_0x6080e(0x1fb)](_0x5df355[_0x6080e(0x1b9)],qs['fields'](_0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x1ff)])),_0x57c0fe[_0x6080e(0x1ce)]=_0x57c0fe[_0x6080e(0x1ce)]['length']?_0x57c0fe[_0x6080e(0x1ce)]:_0x5df355['model'];typeof _0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x1e0)]===_0x6080e(0x1e5)&&(_0x57c0fe['limit']=qs['limit'](_0x5c8d14['query'][_0x6080e(0x1c7)]),_0x57c0fe[_0x6080e(0x20f)]=qs[_0x6080e(0x20f)](_0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x20f)]));_0x57c0fe[_0x6080e(0x1f8)]=qs[_0x6080e(0x1bc)](_0x5c8d14[_0x6080e(0x1e2)]['sort']),_0x57c0fe['where']=qs[_0x6080e(0x20b)](_[_0x6080e(0x1e7)](_0x5c8d14[_0x6080e(0x1e2)],_0x5df355[_0x6080e(0x20b)]),_0x503c17);_0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x1f2)]&&(_0x57c0fe[_0x6080e(0x1ea)]=_[_0x6080e(0x1df)](_0x57c0fe[_0x6080e(0x1ea)],{[Op['or']]:_[_0x6080e(0x20c)](_0x503c17,function(_0x209974){const _0x9e471d=_0x6080e;if(_0x209974[_0x9e471d(0x201)]!==_0x9e471d(0x1d1)){const _0x194f0c={};return _0x194f0c[_0x209974[_0x9e471d(0x1db)]]={[Op[_0x9e471d(0x1de)]]:'%'+_0x5c8d14[_0x9e471d(0x1e2)][_0x9e471d(0x1f2)]+'%'},_0x194f0c;}})}));_0x57c0fe=_['merge']({},_0x57c0fe,_0x5c8d14['options']);const _0x20d966={'where':_0x57c0fe[_0x6080e(0x1ea)]};return db['Trunk'][_0x6080e(0x205)](_0x20d966)[_0x6080e(0x1f6)](function(_0x460fe5){const _0x40e443=_0x6080e;return _0x1913f7[_0x40e443(0x205)]=_0x460fe5,_0x5c8d14[_0x40e443(0x1e2)]['includeAll']&&(_0x57c0fe[_0x40e443(0x1fa)]=[{'all':!![]}]),db['Trunk'][_0x40e443(0x208)](_0x57c0fe);})[_0x6080e(0x1f6)](function(_0x46df94){const _0x7ce4b6=_0x6080e;return _0x1913f7[_0x7ce4b6(0x1d7)]=_0x46df94,_0x1913f7;})[_0x6080e(0x1f6)](respondWithFilteredResult(_0x4a5f4b,_0x57c0fe))[_0x6080e(0x1ba)](handleError(_0x4a5f4b,null));},exports[a769_0x5b804b(0x1d0)]=function(_0x5e5997,_0xb5c740){const _0x3ae169=a769_0x5b804b;let _0x43321d={'raw':![],'where':{'id':_0x5e5997[_0x3ae169(0x1e3)]['id']}};const _0x298d16={};return _0x298d16[_0x3ae169(0x1b9)]=_[_0x3ae169(0x1cb)](db[_0x3ae169(0x1d4)]['rawAttributes']),_0x298d16[_0x3ae169(0x1e2)]=_[_0x3ae169(0x1cb)](_0x5e5997[_0x3ae169(0x1e2)]),_0x298d16[_0x3ae169(0x20b)]=_[_0x3ae169(0x1fb)](_0x298d16['model'],_0x298d16['query']),_0x43321d['attributes']=_[_0x3ae169(0x1fb)](_0x298d16[_0x3ae169(0x1b9)],qs[_0x3ae169(0x1ff)](_0x5e5997[_0x3ae169(0x1e2)]['fields'])),_0x43321d['attributes']=_0x43321d[_0x3ae169(0x1ce)][_0x3ae169(0x211)]?_0x43321d['attributes']:_0x298d16['model'],_0x5e5997['query'][_0x3ae169(0x1d6)]&&(_0x43321d[_0x3ae169(0x1fa)]=[{'all':!![]}]),_0x43321d=_[_0x3ae169(0x1df)]({},_0x43321d,_0x5e5997[_0x3ae169(0x20d)]),db[_0x3ae169(0x1d4)]['findOne'](_0x43321d)[_0x3ae169(0x1f6)](handleEntityNotFound(_0xb5c740,null))[_0x3ae169(0x1f6)](respondWithResult(_0xb5c740,null))['catch'](handleError(_0xb5c740,null));},exports[a769_0x5b804b(0x1bd)]=function(_0x217c3d,_0x5dd742){const _0xbe6980=a769_0x5b804b;let _0x16a255={'where':{'id':_0x217c3d[_0xbe6980(0x1e3)]['id']}};const _0xef57c={};return _0xef57c[_0xbe6980(0x1b9)]=_[_0xbe6980(0x1cb)](db[_0xbe6980(0x1d4)][_0xbe6980(0x1c9)]),_0x16a255[_0xbe6980(0x1ce)]=_['intersection'](_0xef57c[_0xbe6980(0x1b9)],qs[_0xbe6980(0x1ff)](_0x217c3d[_0xbe6980(0x1e2)]['fields'])),_0x16a255['attributes']=_0x16a255[_0xbe6980(0x1ce)][_0xbe6980(0x211)]?_0x16a255[_0xbe6980(0x1ce)]:_0xef57c[_0xbe6980(0x1b9)],_0x217c3d['query'][_0xbe6980(0x1d6)]&&(_0x16a255[_0xbe6980(0x1fa)]=[{'all':!![]}]),_0x16a255=_['merge']({},_0x16a255,_0x217c3d[_0xbe6980(0x20d)]),db[_0xbe6980(0x1d4)]['findOne'](_0x16a255)[_0xbe6980(0x1f6)](handleEntityNotFound(_0x5dd742,null))['then'](function(_0x16fdc4){const _0x5c999d=_0xbe6980;if(_0x16fdc4){let _0x40a4ee=_0x16fdc4[_0x5c999d(0x1d8)]({'plain':!![]});return _0x40a4ee=qs[_0x5c999d(0x1e9)](_0x40a4ee,['id','createdAt',_0x5c999d(0x1d3)]),_0x217c3d[_0x5c999d(0x1fe)]=_[_0x5c999d(0x1e9)](_0x217c3d[_0x5c999d(0x1fe)],['id',_0x5c999d(0x1cf),'updatedAt']),db[_0x5c999d(0x1d4)][_0x5c999d(0x1d9)](_[_0x5c999d(0x1df)](_0x40a4ee,_0x217c3d[_0x5c999d(0x1fe)]),{'include':_0x217c3d[_0x5c999d(0x1e2)][_0x5c999d(0x1d6)]?[{'all':!![]}]:undefined})[_0x5c999d(0x1f6)](function(_0x53d73f){const _0x4060f3=_0x5c999d,_0x10f43b=_0x217c3d[_0x4060f3(0x1d2)]['get']({'plain':!![]});if(!_0x10f43b)throw new Error(_0x4060f3(0x1c8));if(_0x10f43b[_0x4060f3(0x20a)]===_0x4060f3(0x1d2)){const _0x15a961=_0x53d73f[_0x4060f3(0x1d8)]({'plain':!![]}),_0x5883ae=_0x4060f3(0x1cc);return db[_0x4060f3(0x200)][_0x4060f3(0x1b7)]({'where':{'name':_0x5883ae,'userProfileId':_0x10f43b[_0x4060f3(0x1f0)]},'raw':!![]})[_0x4060f3(0x1f6)](function(_0xd242b5){const _0x5b9e23=_0x4060f3;return _0xd242b5&&_0xd242b5[_0x5b9e23(0x212)]===0x0?db[_0x5b9e23(0x1f4)][_0x5b9e23(0x1d9)]({'name':_0x15a961[_0x5b9e23(0x1db)],'resourceId':_0x15a961['id'],'type':_0xd242b5['name'],'sectionId':_0xd242b5['id']},{})['then'](function(){return _0x53d73f;}):_0x53d73f;})[_0x4060f3(0x1ba)](function(_0x11cd84){const _0x21b0ee=_0x4060f3;logger[_0x21b0ee(0x1dd)](_0x21b0ee(0x1c0),_0x11cd84);throw _0x11cd84;});}return _0x53d73f;});}})[_0xbe6980(0x1f6)](respondWithResult(_0x5dd742,0xc9))[_0xbe6980(0x1ba)](handleError(_0x5dd742,null));},exports[a769_0x5b804b(0x1d9)]=function(_0x1b4a35,_0x427026){const _0x11abd3=a769_0x5b804b;let _0x15b41a;return db[_0x11abd3(0x1d4)][_0x11abd3(0x1d9)](_0x1b4a35[_0x11abd3(0x1fe)],{'raw':!![]})[_0x11abd3(0x1f6)](function(_0x823ab7){const _0x212350=_0x11abd3;return _0x15b41a=_0x823ab7,db[_0x212350(0x1d4)]['findAll']({'raw':!![]});})['then'](function(_0x213ebb){const _0x4febf9=_0x11abd3,_0x4b2835=fs[_0x4febf9(0x1b8)](path[_0x4febf9(0x1ee)](config[_0x4febf9(0x1e8)],'files/templates/trunk.ejs'),'utf8'),_0x408a49=fs[_0x4febf9(0x1b8)](path[_0x4febf9(0x1ee)](config[_0x4febf9(0x1e8)],_0x4febf9(0x1c1)),'utf8'),_0x5c2f48=ejs[_0x4febf9(0x1ef)](_0x4b2835,{'trunks':_0x213ebb||[]});fs[_0x4febf9(0x1d5)](_0x4febf9(0x1e1),_0x5c2f48);if(_0x15b41a[_0x4febf9(0x1f5)]){const _0xb2fe3c=ejs[_0x4febf9(0x1ef)](_0x408a49,{'trunks':_0x213ebb||[]});fs[_0x4febf9(0x1d5)](_0x4febf9(0x204),_0xb2fe3c);}})[_0x11abd3(0x1f6)](function(){const _0xc2718a=_0x11abd3;return respondWithRpcPromise(_0xc2718a(0x1bf),_0xc2718a(0x1d9),{'module':'chan_sip.so'});})[_0x11abd3(0x1f6)](function(){const _0x432ece=_0x11abd3,_0x5433fc=_0x1b4a35[_0x432ece(0x1d2)][_0x432ece(0x1d8)]({'plain':!![]});if(!_0x5433fc)throw new Error(_0x432ece(0x1c8));if(_0x5433fc['role']==='user'){const _0x32465c=_0x15b41a[_0x432ece(0x1d8)]({'plain':!![]});return db[_0x432ece(0x200)]['findOne']({'where':{'name':_0x432ece(0x1cc),'userProfileId':_0x5433fc[_0x432ece(0x1f0)]},'raw':!![]})['then'](function(_0x583780){const _0x4cb3ec=_0x432ece;return _0x583780&&_0x583780[_0x4cb3ec(0x212)]===0x0?db[_0x4cb3ec(0x1f4)]['create']({'name':_0x32465c[_0x4cb3ec(0x1db)],'resourceId':_0x32465c['id'],'type':_0x583780['name'],'sectionId':_0x583780['id']},{})['then'](function(){return _0x15b41a;}):_0x15b41a;})['catch'](function(_0x223dbd){const _0x46433e=_0x432ece;logger[_0x46433e(0x1dd)](_0x46433e(0x1c0),_0x223dbd);throw _0x223dbd;});}return _0x15b41a;})['then'](respondWithResult(_0x427026,0xc9))[_0x11abd3(0x1ba)](handleError(_0x427026,null));},exports[a769_0x5b804b(0x203)]=function(_0x27c638,_0x2e3b44){const _0x32a757=a769_0x5b804b;let _0x187a6f;return db[_0x32a757(0x1d4)][_0x32a757(0x1b7)]({'where':{'id':_0x27c638[_0x32a757(0x1e3)]['id']}})[_0x32a757(0x1f6)](handleEntityNotFound(_0x2e3b44,null))['then'](saveUpdates(_0x27c638[_0x32a757(0x1fe)],null))[_0x32a757(0x1f6)](function(_0x2009fc){if(_0x2009fc)return _0x187a6f=_0x2009fc,db['Trunk']['findAll']({'raw':!![]});})[_0x32a757(0x1f6)](function(_0x40ff83){const _0x94b9b2=_0x32a757;if(_0x40ff83){const _0x2e929b=fs[_0x94b9b2(0x1b8)](path[_0x94b9b2(0x1ee)](config[_0x94b9b2(0x1e8)],'files/templates/trunk.ejs'),_0x94b9b2(0x1c2)),_0x5c19af=fs[_0x94b9b2(0x1b8)](path[_0x94b9b2(0x1ee)](config['root'],'files/templates/registry.ejs'),'utf8'),_0x4ba687=ejs[_0x94b9b2(0x1ef)](_0x2e929b,{'trunks':_0x40ff83||[]});fs[_0x94b9b2(0x1d5)]('/etc/asterisk/sip_xcally_trunks.conf',_0x4ba687);const _0x51feb8=ejs['render'](_0x5c19af,{'trunks':_0x40ff83||[]});return fs[_0x94b9b2(0x1d5)](_0x94b9b2(0x204),_0x51feb8),respondWithRpcPromise(_0x94b9b2(0x1bf),_0x94b9b2(0x203),{'module':_0x94b9b2(0x1be)});}return null;})[_0x32a757(0x1f6)](function(_0x5e4c36){if(_0x5e4c36)return _0x187a6f;})[_0x32a757(0x1f6)](respondWithResult(_0x2e3b44,null))[_0x32a757(0x1ba)](handleError(_0x2e3b44,null));},exports[a769_0x5b804b(0x1f3)]=function(_0x37cc37,_0x2aa630){const _0x56d1f2=a769_0x5b804b;return db[_0x56d1f2(0x1d4)][_0x56d1f2(0x1b7)]({'where':{'id':_0x37cc37[_0x56d1f2(0x1e3)]['id']}})[_0x56d1f2(0x1f6)](handleEntityNotFound(_0x2aa630,null))[_0x56d1f2(0x1f6)](removeEntity(_0x2aa630,null))[_0x56d1f2(0x1f6)](function(){const _0x5ccdfe=_0x56d1f2;return db['Trunk'][_0x5ccdfe(0x208)]({'raw':!![]});})[_0x56d1f2(0x1f6)](function(_0x22517b){const _0xe8dc78=_0x56d1f2,_0x3be8f9=fs[_0xe8dc78(0x1b8)](path[_0xe8dc78(0x1ee)](config['root'],_0xe8dc78(0x206)),_0xe8dc78(0x1c2)),_0x5d5384=fs[_0xe8dc78(0x1b8)](path[_0xe8dc78(0x1ee)](config[_0xe8dc78(0x1e8)],_0xe8dc78(0x1c1)),_0xe8dc78(0x1c2)),_0xb7553c=ejs[_0xe8dc78(0x1ef)](_0x3be8f9,{'trunks':_0x22517b}),_0x4a93f9=ejs['render'](_0x5d5384,{'trunks':_0x22517b});return fs[_0xe8dc78(0x1d5)](_0xe8dc78(0x1e1),_0xb7553c),fs['writeFileSync']('/etc/asterisk/sip_xcally_registers.conf',_0x4a93f9),respondWithRpcPromise(_0xe8dc78(0x1bf),_0xe8dc78(0x1f3),{'module':_0xe8dc78(0x1be)});})[_0x56d1f2(0x1ba)](handleError(_0x2aa630,null));};
\ No newline at end of file