Built motion from commit bfc7a72f7045b27461c9a5d1f71c1a658cfd0b8b. Version 3.0.0...
[motion-next.git] / server / api / trunk / trunk.controller.js
index e9fce7e..f218bc7 100644 (file)
@@ -1 +1 @@
-const a643_0x8b8d=['api','includeAll','../../config/logger','map','autoAssociation','json','sequelize','like','offset','http','role','Trunk','type','limit','stack','sort','UserProfileResource','count','catch','filters','clone','create','error','name','order','pick','update','set','chan_sip.so','merge','status','root','keys','where','join','client','intersection','Content-Range','omit','send','options','code','jayson/promise','end','files/templates/trunk.ejs','request\x20sent','info','length','then','fields','render','params','../../config/environment','rawAttributes','Reload','Trunk,\x20%s,\x20%s','query','user','include','stringify','findOne','utf8','updatedAt','message','lodash','rows','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','registry','/etc/asterisk/sip_xcally_registers.conf','ejs','index','body','attributes','show','UserProfileSection','model','../../components/parsers/qs','key','userProfileId','undefined','createdAt','filter','destroy','get','writeFileSync','/etc/asterisk/sip_xcally_trunks.conf','readFileSync','sendStatus','findAll'];(function(_0x35b32f,_0x8b8db0){const _0x27bdc7=function(_0x40aafb){while(--_0x40aafb){_0x35b32f['push'](_0x35b32f['shift']());}};_0x27bdc7(++_0x8b8db0);}(a643_0x8b8d,0xe2));const a643_0x27bd=function(_0x35b32f,_0x8b8db0){_0x35b32f=_0x35b32f-0x0;let _0x27bdc7=a643_0x8b8d[_0x35b32f];return _0x27bdc7;};const _0x1a14ba=a643_0x27bd;'use strict';const path=require('path'),ejs=require(_0x1a14ba('0x15')),fs=require('fs'),_=require(_0x1a14ba('0x10')),qs=require(_0x1a14ba('0x1c')),logger=require(_0x1a14ba('0x2b'))(_0x1a14ba('0x29')),config=require(_0x1a14ba('0x4')),db=require('../../mysqldb')['db'],{Op}=require(_0x1a14ba('0x2f')),jayson=require(_0x1a14ba('0x53')),client=jayson[_0x1a14ba('0x4c')][_0x1a14ba('0x32')]({'port':0x232a});function respondWithRpcPromise(_0x40aafb,_0x26261b,_0x1662c0,_0x5cab09){return new Promise(function(_0x5ea4fc,_0x398117){const _0x147c89=a643_0x27bd,_0x52c988=_0x5cab09||client;return _0x52c988['request'](_0x40aafb,_0x1662c0)[_0x147c89('0x0')](function(_0x3109ff){const _0x1efa3b=_0x147c89;logger[_0x1efa3b('0x57')](_0x1efa3b('0x7'),_0x26261b,_0x1efa3b('0x56')),logger['debug']('Trunk,\x20%s,\x20%s,\x20%s',_0x26261b,_0x1efa3b('0x56'),JSON[_0x1efa3b('0xb')](_0x3109ff));if(_0x3109ff[_0x1efa3b('0x3f')]){if(_0x3109ff[_0x1efa3b('0x3f')][_0x1efa3b('0x52')]===0x1f4)return logger['error'](_0x1efa3b('0x7'),_0x26261b,_0x3109ff[_0x1efa3b('0x3f')][_0x1efa3b('0xf')]),_0x398117(_0x3109ff[_0x1efa3b('0x3f')][_0x1efa3b('0xf')]);return logger['error'](_0x1efa3b('0x7'),_0x26261b,_0x3109ff[_0x1efa3b('0x3f')][_0x1efa3b('0xf')]),_0x5ea4fc(_0x3109ff['error'][_0x1efa3b('0xf')]);}else logger[_0x1efa3b('0x57')](_0x1efa3b('0x7'),_0x26261b,_0x1efa3b('0x56')),_0x5ea4fc(_0x3109ff['result'][_0x1efa3b('0xf')]);})[_0x147c89('0x3b')](function(_0x510b40){const _0x2ddba0=_0x147c89;logger[_0x2ddba0('0x3f')](_0x2ddba0('0x7'),_0x26261b,_0x510b40),_0x398117(_0x510b40);});});}function respondWithResult(_0x5d4580,_0x96f2e){return _0x96f2e=_0x96f2e||0xc8,function(_0x1bc59c){const _0x55f49d=a643_0x27bd;if(_0x1bc59c)return _0x5d4580[_0x55f49d('0x47')](_0x96f2e)[_0x55f49d('0x2e')](_0x1bc59c);};}function respondWithFilteredResult(_0x272a25,_0x7f109a){return function(_0x103c15){const _0x5e3979=a643_0x27bd;if(_0x103c15){const _0x137bd0=_0x103c15[_0x5e3979('0x3a')],_0x5d11b4=_0x7f109a[_0x5e3979('0x31')];let _0x1edb4c=_0x7f109a['offset']+_0x7f109a[_0x5e3979('0x36')],_0xc02268;return _0x1edb4c>=_0x137bd0?(_0x1edb4c=_0x137bd0,_0xc02268=0xc8):_0xc02268=0xce,_0x272a25[_0x5e3979('0x47')](_0xc02268),_0x272a25[_0x5e3979('0x44')](_0x5e3979('0x4e'),_0x5d11b4+'-'+_0x1edb4c+'/'+_0x137bd0)[_0x5e3979('0x2e')](_0x103c15);}return null;};}function saveUpdates(_0x22378b){return function(_0x928947){const _0x26acf1=a643_0x27bd;if(_0x928947)return _0x928947[_0x26acf1('0x43')](_0x22378b)['then'](function(_0x2c46eb){return _0x2c46eb;});return null;};}function removeEntity(_0xcca943){return function(_0x54fadf){const _0x5b6f15=a643_0x27bd;if(_0x54fadf)return _0x54fadf[_0x5b6f15('0x22')]()[_0x5b6f15('0x0')](function(){const _0x169b62=_0x5b6f15,_0x30dcd0=_0x54fadf[_0x169b62('0x23')]({'plain':!![]}),_0x1587c6='Trunks';return db['UserProfileResource']['destroy']({'where':{'type':_0x1587c6,'resourceId':_0x30dcd0['id']}})['then'](function(){return _0x54fadf;});})[_0x5b6f15('0x0')](function(){const _0x1a262d=_0x5b6f15;_0xcca943[_0x1a262d('0x47')](0xcc)[_0x1a262d('0x54')]();});};}function handleEntityNotFound(_0x393680){return function(_0x53c13e){const _0x10fca2=a643_0x27bd;return!_0x53c13e&&_0x393680[_0x10fca2('0x27')](0x194),_0x53c13e;};}function handleError(_0xcb0fcf,_0x288c35){return _0x288c35=_0x288c35||0x1f4,function(_0x57f4bd){const _0x4073d0=a643_0x27bd;logger['error'](_0x57f4bd[_0x4073d0('0x37')]),_0x57f4bd[_0x4073d0('0x40')]&&delete _0x57f4bd[_0x4073d0('0x40')],_0xcb0fcf[_0x4073d0('0x47')](_0x288c35)[_0x4073d0('0x50')](_0x57f4bd);};}exports[_0x1a14ba('0x16')]=function(_0x1b3592,_0x4b8e6b){const _0x1f423c=_0x1a14ba;let _0x18c566={};const _0x51e64f={},_0x394457={'count':0x0,'rows':[]},_0x3248ed=_[_0x1f423c('0x2c')](db[_0x1f423c('0x34')][_0x1f423c('0x5')],function(_0x530840){const _0x2cb6f6=_0x1f423c;return{'name':_0x530840['fieldName'],'type':_0x530840['type'][_0x2cb6f6('0x1d')]};});_0x51e64f['model']=_[_0x1f423c('0x2c')](_0x3248ed,_0x1f423c('0x40')),_0x51e64f[_0x1f423c('0x8')]=_[_0x1f423c('0x49')](_0x1b3592[_0x1f423c('0x8')]),_0x51e64f[_0x1f423c('0x3c')]=_[_0x1f423c('0x4d')](_0x51e64f[_0x1f423c('0x1b')],_0x51e64f[_0x1f423c('0x8')]),_0x18c566[_0x1f423c('0x18')]=_['intersection'](_0x51e64f[_0x1f423c('0x1b')],qs[_0x1f423c('0x1')](_0x1b3592[_0x1f423c('0x8')][_0x1f423c('0x1')])),_0x18c566[_0x1f423c('0x18')]=_0x18c566[_0x1f423c('0x18')][_0x1f423c('0x58')]?_0x18c566[_0x1f423c('0x18')]:_0x51e64f[_0x1f423c('0x1b')];typeof _0x1b3592[_0x1f423c('0x8')]['nolimit']===_0x1f423c('0x1f')&&(_0x18c566[_0x1f423c('0x36')]=qs[_0x1f423c('0x36')](_0x1b3592[_0x1f423c('0x8')]['limit']),_0x18c566[_0x1f423c('0x31')]=qs[_0x1f423c('0x31')](_0x1b3592[_0x1f423c('0x8')][_0x1f423c('0x31')]));_0x18c566[_0x1f423c('0x41')]=qs[_0x1f423c('0x38')](_0x1b3592[_0x1f423c('0x8')][_0x1f423c('0x38')]),_0x18c566[_0x1f423c('0x4a')]=qs[_0x1f423c('0x3c')](_[_0x1f423c('0x42')](_0x1b3592['query'],_0x51e64f[_0x1f423c('0x3c')]),_0x3248ed);_0x1b3592[_0x1f423c('0x8')][_0x1f423c('0x21')]&&(_0x18c566['where']=_['merge'](_0x18c566[_0x1f423c('0x4a')],{[Op['or']]:_[_0x1f423c('0x2c')](_0x3248ed,function(_0x54ffff){const _0x37c201=_0x1f423c;if(_0x54ffff[_0x37c201('0x35')]!=='VIRTUAL'){const _0xcdb6a2={};return _0xcdb6a2[_0x54ffff[_0x37c201('0x40')]]={[Op[_0x37c201('0x30')]]:'%'+_0x1b3592[_0x37c201('0x8')]['filter']+'%'},_0xcdb6a2;}})}));_0x18c566=_[_0x1f423c('0x46')]({},_0x18c566,_0x1b3592[_0x1f423c('0x51')]);const _0x546368={'where':_0x18c566[_0x1f423c('0x4a')]};return db[_0x1f423c('0x34')]['count'](_0x546368)[_0x1f423c('0x0')](function(_0xabf3da){const _0x1b581e=_0x1f423c;return _0x394457[_0x1b581e('0x3a')]=_0xabf3da,_0x1b3592[_0x1b581e('0x8')][_0x1b581e('0x2a')]&&(_0x18c566[_0x1b581e('0xa')]=[{'all':!![]}]),db['Trunk'][_0x1b581e('0x28')](_0x18c566);})['then'](function(_0xf83f93){const _0x16962b=_0x1f423c;return _0x394457[_0x16962b('0x11')]=_0xf83f93,_0x394457;})[_0x1f423c('0x0')](respondWithFilteredResult(_0x4b8e6b,_0x18c566))[_0x1f423c('0x3b')](handleError(_0x4b8e6b,null));},exports[_0x1a14ba('0x19')]=function(_0x2bfdef,_0x7dcb3b){const _0x2cf360=_0x1a14ba;let _0x2a88c6={'raw':![],'where':{'id':_0x2bfdef[_0x2cf360('0x3')]['id']}};const _0x2a222e={};return _0x2a222e[_0x2cf360('0x1b')]=_[_0x2cf360('0x49')](db[_0x2cf360('0x34')][_0x2cf360('0x5')]),_0x2a222e[_0x2cf360('0x8')]=_[_0x2cf360('0x49')](_0x2bfdef[_0x2cf360('0x8')]),_0x2a222e[_0x2cf360('0x3c')]=_[_0x2cf360('0x4d')](_0x2a222e[_0x2cf360('0x1b')],_0x2a222e[_0x2cf360('0x8')]),_0x2a88c6['attributes']=_[_0x2cf360('0x4d')](_0x2a222e[_0x2cf360('0x1b')],qs[_0x2cf360('0x1')](_0x2bfdef[_0x2cf360('0x8')][_0x2cf360('0x1')])),_0x2a88c6[_0x2cf360('0x18')]=_0x2a88c6[_0x2cf360('0x18')]['length']?_0x2a88c6[_0x2cf360('0x18')]:_0x2a222e['model'],_0x2bfdef[_0x2cf360('0x8')][_0x2cf360('0x2a')]&&(_0x2a88c6[_0x2cf360('0xa')]=[{'all':!![]}]),_0x2a88c6=_[_0x2cf360('0x46')]({},_0x2a88c6,_0x2bfdef['options']),db[_0x2cf360('0x34')][_0x2cf360('0xc')](_0x2a88c6)[_0x2cf360('0x0')](handleEntityNotFound(_0x7dcb3b,null))['then'](respondWithResult(_0x7dcb3b,null))[_0x2cf360('0x3b')](handleError(_0x7dcb3b,null));},exports[_0x1a14ba('0x3d')]=function(_0x4e97e8,_0x48e457){const _0x3dd634=_0x1a14ba;let _0x2494da={'where':{'id':_0x4e97e8[_0x3dd634('0x3')]['id']}};const _0x1a448b={};return _0x1a448b[_0x3dd634('0x1b')]=_['keys'](db[_0x3dd634('0x34')]['rawAttributes']),_0x2494da[_0x3dd634('0x18')]=_[_0x3dd634('0x4d')](_0x1a448b['model'],qs[_0x3dd634('0x1')](_0x4e97e8[_0x3dd634('0x8')][_0x3dd634('0x1')])),_0x2494da[_0x3dd634('0x18')]=_0x2494da['attributes'][_0x3dd634('0x58')]?_0x2494da['attributes']:_0x1a448b[_0x3dd634('0x1b')],_0x4e97e8[_0x3dd634('0x8')][_0x3dd634('0x2a')]&&(_0x2494da['include']=[{'all':!![]}]),_0x2494da=_['merge']({},_0x2494da,_0x4e97e8[_0x3dd634('0x51')]),db[_0x3dd634('0x34')][_0x3dd634('0xc')](_0x2494da)[_0x3dd634('0x0')](handleEntityNotFound(_0x48e457,null))['then'](function(_0x3273f6){const _0x213363=_0x3dd634;if(_0x3273f6){let _0x1f124b=_0x3273f6['get']({'plain':!![]});return _0x1f124b=qs[_0x213363('0x4f')](_0x1f124b,['id',_0x213363('0x20'),_0x213363('0xe')]),_0x4e97e8[_0x213363('0x17')]=_[_0x213363('0x4f')](_0x4e97e8[_0x213363('0x17')],['id',_0x213363('0x20'),_0x213363('0xe')]),db[_0x213363('0x34')][_0x213363('0x3e')](_[_0x213363('0x46')](_0x1f124b,_0x4e97e8[_0x213363('0x17')]),{'include':_0x4e97e8[_0x213363('0x8')]['includeAll']?[{'all':!![]}]:undefined})[_0x213363('0x0')](function(_0xe6224a){const _0x37ee63=_0x213363,_0x466416=_0x4e97e8[_0x37ee63('0x9')][_0x37ee63('0x23')]({'plain':!![]});if(!_0x466416)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x466416[_0x37ee63('0x33')]==='user'){const _0x8ab916=_0xe6224a[_0x37ee63('0x23')]({'plain':!![]}),_0x479c85='Trunks';return db[_0x37ee63('0x1a')]['findOne']({'where':{'name':_0x479c85,'userProfileId':_0x466416[_0x37ee63('0x1e')]},'raw':!![]})[_0x37ee63('0x0')](function(_0x2a88ed){const _0x279903=_0x37ee63;return _0x2a88ed&&_0x2a88ed[_0x279903('0x2d')]===0x0?db[_0x279903('0x39')][_0x279903('0x3e')]({'name':_0x8ab916['name'],'resourceId':_0x8ab916['id'],'type':_0x2a88ed[_0x279903('0x40')],'sectionId':_0x2a88ed['id']},{})[_0x279903('0x0')](function(){return _0xe6224a;}):_0xe6224a;})[_0x37ee63('0x3b')](function(_0x99d42f){const _0x3cb353=_0x37ee63;logger['error'](_0x3cb353('0x12'),_0x99d42f);throw _0x99d42f;});}return _0xe6224a;});}})[_0x3dd634('0x0')](respondWithResult(_0x48e457,0xc9))['catch'](handleError(_0x48e457,null));},exports[_0x1a14ba('0x3e')]=function(_0x45bdd8,_0x56e066){const _0x2fcf63=_0x1a14ba;let _0x33da0c;return db[_0x2fcf63('0x34')][_0x2fcf63('0x3e')](_0x45bdd8[_0x2fcf63('0x17')],{'raw':!![]})[_0x2fcf63('0x0')](function(_0x373609){const _0x169f06=_0x2fcf63;return _0x33da0c=_0x373609,db[_0x169f06('0x34')][_0x169f06('0x28')]({'raw':!![]});})[_0x2fcf63('0x0')](function(_0x368657){const _0x2bdbd5=_0x2fcf63,_0x323a42=fs[_0x2bdbd5('0x26')](path['join'](config[_0x2bdbd5('0x48')],_0x2bdbd5('0x55')),_0x2bdbd5('0xd')),_0x56a0e5=fs['readFileSync'](path[_0x2bdbd5('0x4b')](config[_0x2bdbd5('0x48')],'files/templates/registry.ejs'),_0x2bdbd5('0xd')),_0xf8410c=ejs['render'](_0x323a42,{'trunks':_0x368657||[]});fs[_0x2bdbd5('0x24')]('/etc/asterisk/sip_xcally_trunks.conf',_0xf8410c);if(_0x33da0c[_0x2bdbd5('0x13')]){const _0xb41d29=ejs[_0x2bdbd5('0x2')](_0x56a0e5,{'trunks':_0x368657||[]});fs['writeFileSync'](_0x2bdbd5('0x14'),_0xb41d29);}})[_0x2fcf63('0x0')](function(){const _0x2a8a0d=_0x2fcf63;return respondWithRpcPromise('Reload',_0x2a8a0d('0x3e'),{'module':'chan_sip.so'});})[_0x2fcf63('0x0')](function(){const _0x276ff4=_0x2fcf63,_0x135c5f=_0x45bdd8[_0x276ff4('0x9')][_0x276ff4('0x23')]({'plain':!![]});if(!_0x135c5f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x135c5f[_0x276ff4('0x33')]===_0x276ff4('0x9')){const _0x5007b6=_0x33da0c[_0x276ff4('0x23')]({'plain':!![]});return db[_0x276ff4('0x1a')][_0x276ff4('0xc')]({'where':{'name':'Trunks','userProfileId':_0x135c5f['userProfileId']},'raw':!![]})[_0x276ff4('0x0')](function(_0x465eeb){const _0x2ba007=_0x276ff4;return _0x465eeb&&_0x465eeb['autoAssociation']===0x0?db[_0x2ba007('0x39')][_0x2ba007('0x3e')]({'name':_0x5007b6[_0x2ba007('0x40')],'resourceId':_0x5007b6['id'],'type':_0x465eeb['name'],'sectionId':_0x465eeb['id']},{})['then'](function(){return _0x33da0c;}):_0x33da0c;})[_0x276ff4('0x3b')](function(_0x1219f4){const _0x5915d4=_0x276ff4;logger[_0x5915d4('0x3f')](_0x5915d4('0x12'),_0x1219f4);throw _0x1219f4;});}return _0x33da0c;})[_0x2fcf63('0x0')](respondWithResult(_0x56e066,0xc9))[_0x2fcf63('0x3b')](handleError(_0x56e066,null));},exports[_0x1a14ba('0x43')]=function(_0x328491,_0x384433){const _0x57d421=_0x1a14ba;let _0x58eef2;return db[_0x57d421('0x34')][_0x57d421('0xc')]({'where':{'id':_0x328491[_0x57d421('0x3')]['id']}})[_0x57d421('0x0')](handleEntityNotFound(_0x384433,null))['then'](saveUpdates(_0x328491[_0x57d421('0x17')],null))[_0x57d421('0x0')](function(_0x4ea338){const _0x51c373=_0x57d421;if(_0x4ea338)return _0x58eef2=_0x4ea338,db[_0x51c373('0x34')][_0x51c373('0x28')]({'raw':!![]});})[_0x57d421('0x0')](function(_0x2f8578){const _0x85a63a=_0x57d421;if(_0x2f8578){const _0x321a80=fs[_0x85a63a('0x26')](path[_0x85a63a('0x4b')](config[_0x85a63a('0x48')],_0x85a63a('0x55')),'utf8'),_0x2c4aec=fs['readFileSync'](path[_0x85a63a('0x4b')](config['root'],'files/templates/registry.ejs'),_0x85a63a('0xd')),_0x155264=ejs[_0x85a63a('0x2')](_0x321a80,{'trunks':_0x2f8578||[]});fs[_0x85a63a('0x24')]('/etc/asterisk/sip_xcally_trunks.conf',_0x155264);const _0x1596cd=ejs[_0x85a63a('0x2')](_0x2c4aec,{'trunks':_0x2f8578||[]});return fs[_0x85a63a('0x24')](_0x85a63a('0x14'),_0x1596cd),respondWithRpcPromise('Reload','update',{'module':_0x85a63a('0x45')});}return null;})[_0x57d421('0x0')](function(_0x524fd2){if(_0x524fd2)return _0x58eef2;})[_0x57d421('0x0')](respondWithResult(_0x384433,null))['catch'](handleError(_0x384433,null));},exports['destroy']=function(_0x3dc24a,_0x1c6af0){const _0x3328a5=_0x1a14ba;return db['Trunk'][_0x3328a5('0xc')]({'where':{'id':_0x3dc24a[_0x3328a5('0x3')]['id']}})[_0x3328a5('0x0')](handleEntityNotFound(_0x1c6af0,null))[_0x3328a5('0x0')](removeEntity(_0x1c6af0,null))[_0x3328a5('0x0')](function(){const _0x5eaf89=_0x3328a5;return db['Trunk'][_0x5eaf89('0x28')]({'raw':!![]});})[_0x3328a5('0x0')](function(_0x4abd2d){const _0x32bd0a=_0x3328a5,_0xa04844=fs[_0x32bd0a('0x26')](path[_0x32bd0a('0x4b')](config[_0x32bd0a('0x48')],_0x32bd0a('0x55')),_0x32bd0a('0xd')),_0x11b314=fs['readFileSync'](path['join'](config[_0x32bd0a('0x48')],'files/templates/registry.ejs'),_0x32bd0a('0xd')),_0x2c01a2=ejs[_0x32bd0a('0x2')](_0xa04844,{'trunks':_0x4abd2d}),_0x252a85=ejs[_0x32bd0a('0x2')](_0x11b314,{'trunks':_0x4abd2d});return fs[_0x32bd0a('0x24')](_0x32bd0a('0x25'),_0x2c01a2),fs[_0x32bd0a('0x24')](_0x32bd0a('0x14'),_0x252a85),respondWithRpcPromise(_0x32bd0a('0x6'),'destroy',{'module':'chan_sip.so'});})[_0x3328a5('0x3b')](handleError(_0x1c6af0,null));};
\ No newline at end of file
+const a643_0x19d9=['/etc/asterisk/sip_xcally_registers.conf','json','map','fieldName','end','catch','Trunk','lodash','get','files/templates/trunk.ejs','where','options','nolimit','Trunk,\x20%s,\x20%s,\x20%s','update','Content-Range','like','stringify','path','updatedAt','render','fields','length','set','clone','result','Reload','order','UserProfileSection','type','attributes','destroy','root','ejs','rows','findAll','Unable\x20to\x20retrieve\x20the\x20current\x20user','limit','Trunks','/etc/asterisk/sip_xcally_trunks.conf','undefined','send','api','debug','merge','info','name','offset','create','filter','then','jayson/promise','filters','show','findOne','message','UserProfileResource','key','user','registry','includeAll','model','count','request','status','intersection','utf8','omit','http','params','join','role','request\x20sent','query','sort','createdAt','rawAttributes','error','../../mysqldb','chan_sip.so','include','Trunk,\x20%s,\x20%s','userProfileId','writeFileSync','pick','body','readFileSync','sequelize','keys','files/templates/registry.ejs'];(function(_0x1f8a8d,_0x19d952){const _0x57ca02=function(_0xcc9a10){while(--_0xcc9a10){_0x1f8a8d['push'](_0x1f8a8d['shift']());}};_0x57ca02(++_0x19d952);}(a643_0x19d9,0x8b));const a643_0x57ca=function(_0x1f8a8d,_0x19d952){_0x1f8a8d=_0x1f8a8d-0x0;let _0x57ca02=a643_0x19d9[_0x1f8a8d];return _0x57ca02;};const _0x66f912=a643_0x57ca;'use strict';const path=require(_0x66f912('0x3b')),ejs=require(_0x66f912('0x4a')),fs=require('fs'),_=require(_0x66f912('0x30')),qs=require('../../components/parsers/qs'),logger=require('../../config/logger')(_0x66f912('0x53')),config=require('../../config/environment'),db=require(_0x66f912('0x1d'))['db'],{Op}=require(_0x66f912('0x26')),jayson=require(_0x66f912('0x2')),client=jayson['client'][_0x66f912('0x13')]({'port':0x232a});function respondWithRpcPromise(_0xcc9a10,_0x24a135,_0x4ed1a2,_0x460487){return new Promise(function(_0x198305,_0x120b84){const _0x2bd5e5=a643_0x57ca,_0x88a462=_0x460487||client;return _0x88a462[_0x2bd5e5('0xe')](_0xcc9a10,_0x4ed1a2)[_0x2bd5e5('0x1')](function(_0x3c20a4){const _0x56d661=_0x2bd5e5;logger[_0x56d661('0x56')]('Trunk,\x20%s,\x20%s',_0x24a135,_0x56d661('0x17')),logger[_0x56d661('0x54')](_0x56d661('0x36'),_0x24a135,_0x56d661('0x17'),JSON[_0x56d661('0x3a')](_0x3c20a4));if(_0x3c20a4[_0x56d661('0x1c')]){if(_0x3c20a4[_0x56d661('0x1c')]['code']===0x1f4)return logger[_0x56d661('0x1c')](_0x56d661('0x20'),_0x24a135,_0x3c20a4[_0x56d661('0x1c')][_0x56d661('0x6')]),_0x120b84(_0x3c20a4['error']['message']);return logger[_0x56d661('0x1c')](_0x56d661('0x20'),_0x24a135,_0x3c20a4[_0x56d661('0x1c')][_0x56d661('0x6')]),_0x198305(_0x3c20a4[_0x56d661('0x1c')]['message']);}else logger['info'](_0x56d661('0x20'),_0x24a135,_0x56d661('0x17')),_0x198305(_0x3c20a4[_0x56d661('0x42')][_0x56d661('0x6')]);})[_0x2bd5e5('0x2e')](function(_0x319df5){const _0x2f70b4=_0x2bd5e5;logger[_0x2f70b4('0x1c')]('Trunk,\x20%s,\x20%s',_0x24a135,_0x319df5),_0x120b84(_0x319df5);});});}function respondWithResult(_0x3cc97d,_0x496188){return _0x496188=_0x496188||0xc8,function(_0x3214e3){const _0x3b2300=a643_0x57ca;if(_0x3214e3)return _0x3cc97d[_0x3b2300('0xf')](_0x496188)[_0x3b2300('0x2a')](_0x3214e3);};}function respondWithFilteredResult(_0x373f87,_0x5c594a){return function(_0xd4b39b){const _0x243834=a643_0x57ca;if(_0xd4b39b){const _0x78e4ae=_0xd4b39b['count'],_0x1f1edd=_0x5c594a[_0x243834('0x58')];let _0x2b3efa=_0x5c594a[_0x243834('0x58')]+_0x5c594a['limit'],_0x3a767d;return _0x2b3efa>=_0x78e4ae?(_0x2b3efa=_0x78e4ae,_0x3a767d=0xc8):_0x3a767d=0xce,_0x373f87[_0x243834('0xf')](_0x3a767d),_0x373f87[_0x243834('0x40')](_0x243834('0x38'),_0x1f1edd+'-'+_0x2b3efa+'/'+_0x78e4ae)[_0x243834('0x2a')](_0xd4b39b);}return null;};}function saveUpdates(_0x5cd59c){return function(_0xe56ea7){const _0x66a3a4=a643_0x57ca;if(_0xe56ea7)return _0xe56ea7[_0x66a3a4('0x37')](_0x5cd59c)[_0x66a3a4('0x1')](function(_0x36542e){return _0x36542e;});return null;};}function removeEntity(_0x293923){return function(_0x3f3b64){const _0x5a080e=a643_0x57ca;if(_0x3f3b64)return _0x3f3b64[_0x5a080e('0x48')]()[_0x5a080e('0x1')](function(){const _0x1a3dcd=_0x5a080e,_0x279b49=_0x3f3b64[_0x1a3dcd('0x31')]({'plain':!![]}),_0x4a11f3=_0x1a3dcd('0x4f');return db['UserProfileResource'][_0x1a3dcd('0x48')]({'where':{'type':_0x4a11f3,'resourceId':_0x279b49['id']}})[_0x1a3dcd('0x1')](function(){return _0x3f3b64;});})[_0x5a080e('0x1')](function(){const _0x4d3f59=_0x5a080e;_0x293923[_0x4d3f59('0xf')](0xcc)[_0x4d3f59('0x2d')]();});};}function handleEntityNotFound(_0x4094b4){return function(_0x32b0ae){return!_0x32b0ae&&_0x4094b4['sendStatus'](0x194),_0x32b0ae;};}function handleError(_0x150c8a,_0x566d29){return _0x566d29=_0x566d29||0x1f4,function(_0xf3b263){const _0x5d542d=a643_0x57ca;logger['error'](_0xf3b263['stack']),_0xf3b263[_0x5d542d('0x57')]&&delete _0xf3b263['name'],_0x150c8a[_0x5d542d('0xf')](_0x566d29)[_0x5d542d('0x52')](_0xf3b263);};}exports['index']=function(_0x4be71d,_0x5c44f0){const _0x2d10cb=_0x66f912;let _0x4d2649={};const _0x1879b8={},_0x34f809={'count':0x0,'rows':[]},_0x3edcd5=_[_0x2d10cb('0x2b')](db[_0x2d10cb('0x2f')][_0x2d10cb('0x1b')],function(_0x3ffb03){const _0x335db5=_0x2d10cb;return{'name':_0x3ffb03[_0x335db5('0x2c')],'type':_0x3ffb03[_0x335db5('0x46')][_0x335db5('0x8')]};});_0x1879b8[_0x2d10cb('0xc')]=_[_0x2d10cb('0x2b')](_0x3edcd5,_0x2d10cb('0x57')),_0x1879b8[_0x2d10cb('0x18')]=_[_0x2d10cb('0x27')](_0x4be71d[_0x2d10cb('0x18')]),_0x1879b8[_0x2d10cb('0x3')]=_[_0x2d10cb('0x10')](_0x1879b8[_0x2d10cb('0xc')],_0x1879b8[_0x2d10cb('0x18')]),_0x4d2649['attributes']=_[_0x2d10cb('0x10')](_0x1879b8['model'],qs[_0x2d10cb('0x3e')](_0x4be71d[_0x2d10cb('0x18')][_0x2d10cb('0x3e')])),_0x4d2649[_0x2d10cb('0x47')]=_0x4d2649[_0x2d10cb('0x47')][_0x2d10cb('0x3f')]?_0x4d2649[_0x2d10cb('0x47')]:_0x1879b8[_0x2d10cb('0xc')];typeof _0x4be71d[_0x2d10cb('0x18')][_0x2d10cb('0x35')]===_0x2d10cb('0x51')&&(_0x4d2649[_0x2d10cb('0x4e')]=qs[_0x2d10cb('0x4e')](_0x4be71d[_0x2d10cb('0x18')]['limit']),_0x4d2649[_0x2d10cb('0x58')]=qs[_0x2d10cb('0x58')](_0x4be71d[_0x2d10cb('0x18')][_0x2d10cb('0x58')]));_0x4d2649[_0x2d10cb('0x44')]=qs[_0x2d10cb('0x19')](_0x4be71d[_0x2d10cb('0x18')]['sort']),_0x4d2649[_0x2d10cb('0x33')]=qs[_0x2d10cb('0x3')](_[_0x2d10cb('0x23')](_0x4be71d[_0x2d10cb('0x18')],_0x1879b8[_0x2d10cb('0x3')]),_0x3edcd5);_0x4be71d[_0x2d10cb('0x18')]['filter']&&(_0x4d2649[_0x2d10cb('0x33')]=_['merge'](_0x4d2649['where'],{[Op['or']]:_[_0x2d10cb('0x2b')](_0x3edcd5,function(_0x31dba2){const _0x52a7ad=_0x2d10cb;if(_0x31dba2['type']!=='VIRTUAL'){const _0x267164={};return _0x267164[_0x31dba2[_0x52a7ad('0x57')]]={[Op[_0x52a7ad('0x39')]]:'%'+_0x4be71d[_0x52a7ad('0x18')][_0x52a7ad('0x0')]+'%'},_0x267164;}})}));_0x4d2649=_['merge']({},_0x4d2649,_0x4be71d[_0x2d10cb('0x34')]);const _0x188d08={'where':_0x4d2649[_0x2d10cb('0x33')]};return db[_0x2d10cb('0x2f')][_0x2d10cb('0xd')](_0x188d08)[_0x2d10cb('0x1')](function(_0x4465bb){const _0x248f53=_0x2d10cb;return _0x34f809[_0x248f53('0xd')]=_0x4465bb,_0x4be71d[_0x248f53('0x18')][_0x248f53('0xb')]&&(_0x4d2649[_0x248f53('0x1f')]=[{'all':!![]}]),db[_0x248f53('0x2f')]['findAll'](_0x4d2649);})[_0x2d10cb('0x1')](function(_0x4a567e){const _0x40e9b4=_0x2d10cb;return _0x34f809[_0x40e9b4('0x4b')]=_0x4a567e,_0x34f809;})['then'](respondWithFilteredResult(_0x5c44f0,_0x4d2649))[_0x2d10cb('0x2e')](handleError(_0x5c44f0,null));},exports[_0x66f912('0x4')]=function(_0x3152fd,_0x2efba3){const _0x38a5a3=_0x66f912;let _0x521fb7={'raw':![],'where':{'id':_0x3152fd[_0x38a5a3('0x14')]['id']}};const _0x1b8be1={};return _0x1b8be1[_0x38a5a3('0xc')]=_[_0x38a5a3('0x27')](db[_0x38a5a3('0x2f')][_0x38a5a3('0x1b')]),_0x1b8be1[_0x38a5a3('0x18')]=_['keys'](_0x3152fd['query']),_0x1b8be1[_0x38a5a3('0x3')]=_['intersection'](_0x1b8be1[_0x38a5a3('0xc')],_0x1b8be1[_0x38a5a3('0x18')]),_0x521fb7[_0x38a5a3('0x47')]=_[_0x38a5a3('0x10')](_0x1b8be1['model'],qs[_0x38a5a3('0x3e')](_0x3152fd[_0x38a5a3('0x18')]['fields'])),_0x521fb7['attributes']=_0x521fb7[_0x38a5a3('0x47')]['length']?_0x521fb7['attributes']:_0x1b8be1['model'],_0x3152fd[_0x38a5a3('0x18')][_0x38a5a3('0xb')]&&(_0x521fb7['include']=[{'all':!![]}]),_0x521fb7=_[_0x38a5a3('0x55')]({},_0x521fb7,_0x3152fd[_0x38a5a3('0x34')]),db[_0x38a5a3('0x2f')][_0x38a5a3('0x5')](_0x521fb7)[_0x38a5a3('0x1')](handleEntityNotFound(_0x2efba3,null))[_0x38a5a3('0x1')](respondWithResult(_0x2efba3,null))[_0x38a5a3('0x2e')](handleError(_0x2efba3,null));},exports[_0x66f912('0x41')]=function(_0x239c1e,_0x89000){const _0xe7ccfc=_0x66f912;let _0x1108c7={'where':{'id':_0x239c1e['params']['id']}};const _0x8fe3c2={};return _0x8fe3c2[_0xe7ccfc('0xc')]=_[_0xe7ccfc('0x27')](db['Trunk'][_0xe7ccfc('0x1b')]),_0x1108c7[_0xe7ccfc('0x47')]=_[_0xe7ccfc('0x10')](_0x8fe3c2[_0xe7ccfc('0xc')],qs[_0xe7ccfc('0x3e')](_0x239c1e['query'][_0xe7ccfc('0x3e')])),_0x1108c7[_0xe7ccfc('0x47')]=_0x1108c7[_0xe7ccfc('0x47')][_0xe7ccfc('0x3f')]?_0x1108c7['attributes']:_0x8fe3c2[_0xe7ccfc('0xc')],_0x239c1e[_0xe7ccfc('0x18')][_0xe7ccfc('0xb')]&&(_0x1108c7[_0xe7ccfc('0x1f')]=[{'all':!![]}]),_0x1108c7=_['merge']({},_0x1108c7,_0x239c1e[_0xe7ccfc('0x34')]),db[_0xe7ccfc('0x2f')]['findOne'](_0x1108c7)['then'](handleEntityNotFound(_0x89000,null))[_0xe7ccfc('0x1')](function(_0x3c7164){const _0x9a753b=_0xe7ccfc;if(_0x3c7164){let _0x18a4ab=_0x3c7164[_0x9a753b('0x31')]({'plain':!![]});return _0x18a4ab=qs['omit'](_0x18a4ab,['id',_0x9a753b('0x1a'),_0x9a753b('0x3c')]),_0x239c1e[_0x9a753b('0x24')]=_[_0x9a753b('0x12')](_0x239c1e[_0x9a753b('0x24')],['id',_0x9a753b('0x1a'),_0x9a753b('0x3c')]),db[_0x9a753b('0x2f')][_0x9a753b('0x59')](_['merge'](_0x18a4ab,_0x239c1e[_0x9a753b('0x24')]),{'include':_0x239c1e[_0x9a753b('0x18')][_0x9a753b('0xb')]?[{'all':!![]}]:undefined})[_0x9a753b('0x1')](function(_0x129de6){const _0x47416a=_0x9a753b,_0x26dddc=_0x239c1e[_0x47416a('0x9')][_0x47416a('0x31')]({'plain':!![]});if(!_0x26dddc)throw new Error(_0x47416a('0x4d'));if(_0x26dddc[_0x47416a('0x16')]==='user'){const _0x382498=_0x129de6[_0x47416a('0x31')]({'plain':!![]}),_0x298026=_0x47416a('0x4f');return db['UserProfileSection'][_0x47416a('0x5')]({'where':{'name':_0x298026,'userProfileId':_0x26dddc[_0x47416a('0x21')]},'raw':!![]})[_0x47416a('0x1')](function(_0x2f42f){const _0x516753=_0x47416a;return _0x2f42f&&_0x2f42f['autoAssociation']===0x0?db[_0x516753('0x7')][_0x516753('0x59')]({'name':_0x382498[_0x516753('0x57')],'resourceId':_0x382498['id'],'type':_0x2f42f['name'],'sectionId':_0x2f42f['id']},{})['then'](function(){return _0x129de6;}):_0x129de6;})[_0x47416a('0x2e')](function(_0xc680a5){const _0x2ff731=_0x47416a;logger[_0x2ff731('0x1c')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xc680a5);throw _0xc680a5;});}return _0x129de6;});}})[_0xe7ccfc('0x1')](respondWithResult(_0x89000,0xc9))[_0xe7ccfc('0x2e')](handleError(_0x89000,null));},exports[_0x66f912('0x59')]=function(_0x40ed1d,_0x53c467){const _0x4e6293=_0x66f912;let _0x2186c1;return db[_0x4e6293('0x2f')][_0x4e6293('0x59')](_0x40ed1d[_0x4e6293('0x24')],{'raw':!![]})[_0x4e6293('0x1')](function(_0x19d841){const _0x240d4f=_0x4e6293;return _0x2186c1=_0x19d841,db['Trunk'][_0x240d4f('0x4c')]({'raw':!![]});})[_0x4e6293('0x1')](function(_0x593a9e){const _0x1a2be3=_0x4e6293,_0x21df53=fs[_0x1a2be3('0x25')](path['join'](config['root'],_0x1a2be3('0x32')),_0x1a2be3('0x11')),_0x57adbe=fs[_0x1a2be3('0x25')](path[_0x1a2be3('0x15')](config[_0x1a2be3('0x49')],_0x1a2be3('0x28')),_0x1a2be3('0x11')),_0x565ef4=ejs[_0x1a2be3('0x3d')](_0x21df53,{'trunks':_0x593a9e||[]});fs[_0x1a2be3('0x22')](_0x1a2be3('0x50'),_0x565ef4);if(_0x2186c1[_0x1a2be3('0xa')]){const _0x2fe572=ejs[_0x1a2be3('0x3d')](_0x57adbe,{'trunks':_0x593a9e||[]});fs['writeFileSync'](_0x1a2be3('0x29'),_0x2fe572);}})[_0x4e6293('0x1')](function(){const _0x27b9aa=_0x4e6293;return respondWithRpcPromise('Reload',_0x27b9aa('0x59'),{'module':_0x27b9aa('0x1e')});})['then'](function(){const _0x1691ea=_0x4e6293,_0x46042b=_0x40ed1d['user'][_0x1691ea('0x31')]({'plain':!![]});if(!_0x46042b)throw new Error(_0x1691ea('0x4d'));if(_0x46042b[_0x1691ea('0x16')]==='user'){const _0x53ead3=_0x2186c1[_0x1691ea('0x31')]({'plain':!![]});return db[_0x1691ea('0x45')]['findOne']({'where':{'name':_0x1691ea('0x4f'),'userProfileId':_0x46042b[_0x1691ea('0x21')]},'raw':!![]})[_0x1691ea('0x1')](function(_0x33e740){const _0x1fffde=_0x1691ea;return _0x33e740&&_0x33e740['autoAssociation']===0x0?db[_0x1fffde('0x7')]['create']({'name':_0x53ead3['name'],'resourceId':_0x53ead3['id'],'type':_0x33e740[_0x1fffde('0x57')],'sectionId':_0x33e740['id']},{})[_0x1fffde('0x1')](function(){return _0x2186c1;}):_0x2186c1;})['catch'](function(_0xe40cbe){const _0x4111c2=_0x1691ea;logger[_0x4111c2('0x1c')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xe40cbe);throw _0xe40cbe;});}return _0x2186c1;})[_0x4e6293('0x1')](respondWithResult(_0x53c467,0xc9))['catch'](handleError(_0x53c467,null));},exports['update']=function(_0x1bc10f,_0x3ba3a9){const _0x1fcb6a=_0x66f912;let _0x43da1e;return db[_0x1fcb6a('0x2f')][_0x1fcb6a('0x5')]({'where':{'id':_0x1bc10f['params']['id']}})[_0x1fcb6a('0x1')](handleEntityNotFound(_0x3ba3a9,null))[_0x1fcb6a('0x1')](saveUpdates(_0x1bc10f[_0x1fcb6a('0x24')],null))[_0x1fcb6a('0x1')](function(_0x5595d6){const _0x4bef9a=_0x1fcb6a;if(_0x5595d6)return _0x43da1e=_0x5595d6,db[_0x4bef9a('0x2f')]['findAll']({'raw':!![]});})[_0x1fcb6a('0x1')](function(_0x2ea6b9){const _0x34b518=_0x1fcb6a;if(_0x2ea6b9){const _0x49d4c7=fs[_0x34b518('0x25')](path[_0x34b518('0x15')](config[_0x34b518('0x49')],_0x34b518('0x32')),_0x34b518('0x11')),_0x52343b=fs[_0x34b518('0x25')](path[_0x34b518('0x15')](config[_0x34b518('0x49')],_0x34b518('0x28')),'utf8'),_0x3a34a9=ejs['render'](_0x49d4c7,{'trunks':_0x2ea6b9||[]});fs[_0x34b518('0x22')](_0x34b518('0x50'),_0x3a34a9);const _0x12edf6=ejs[_0x34b518('0x3d')](_0x52343b,{'trunks':_0x2ea6b9||[]});return fs[_0x34b518('0x22')](_0x34b518('0x29'),_0x12edf6),respondWithRpcPromise(_0x34b518('0x43'),_0x34b518('0x37'),{'module':'chan_sip.so'});}return null;})[_0x1fcb6a('0x1')](function(_0x576c8e){if(_0x576c8e)return _0x43da1e;})[_0x1fcb6a('0x1')](respondWithResult(_0x3ba3a9,null))[_0x1fcb6a('0x2e')](handleError(_0x3ba3a9,null));},exports[_0x66f912('0x48')]=function(_0x14d4f2,_0x31e3cd){const _0x3a0ae1=_0x66f912;return db[_0x3a0ae1('0x2f')][_0x3a0ae1('0x5')]({'where':{'id':_0x14d4f2[_0x3a0ae1('0x14')]['id']}})[_0x3a0ae1('0x1')](handleEntityNotFound(_0x31e3cd,null))[_0x3a0ae1('0x1')](removeEntity(_0x31e3cd,null))[_0x3a0ae1('0x1')](function(){const _0x38b298=_0x3a0ae1;return db[_0x38b298('0x2f')][_0x38b298('0x4c')]({'raw':!![]});})[_0x3a0ae1('0x1')](function(_0x449fda){const _0x47fd39=_0x3a0ae1,_0x29d643=fs['readFileSync'](path['join'](config[_0x47fd39('0x49')],'files/templates/trunk.ejs'),'utf8'),_0x103a59=fs[_0x47fd39('0x25')](path[_0x47fd39('0x15')](config['root'],_0x47fd39('0x28')),_0x47fd39('0x11')),_0x131fdf=ejs[_0x47fd39('0x3d')](_0x29d643,{'trunks':_0x449fda}),_0x5aaa67=ejs['render'](_0x103a59,{'trunks':_0x449fda});return fs['writeFileSync'](_0x47fd39('0x50'),_0x131fdf),fs[_0x47fd39('0x22')](_0x47fd39('0x29'),_0x5aaa67),respondWithRpcPromise(_0x47fd39('0x43'),'destroy',{'module':_0x47fd39('0x1e')});})[_0x3a0ae1('0x2e')](handleError(_0x31e3cd,null));};
\ No newline at end of file