Built motion from commit a9fb64cc6defd8fb3a5cc199221f878e91c0e969. Version 3.0.0...
[motion-next.git] / server / api / trunk / trunk.controller.js
index 54cf2d8..5f7d9f9 100644 (file)
@@ -1 +1 @@
-const a643_0x2425=['filter','stringify','findOne','error','http','query','writeFileSync','length','Content-Range','intersection','type','then','fieldName','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','model','userProfileId','info','fields','Trunk,\x20%s,\x20%s','name','registry','count','pick','omit','keys','offset','result','files/templates/registry.ejs','lodash','attributes','api','path','../../config/logger','Trunk','autoAssociation','set','../../config/environment','request','order','../../mysqldb','includeAll','include','undefined','files/templates/trunk.ejs','VIRTUAL','UserProfileResource','UserProfileSection','sequelize','body','findAll','role','Trunks','chan_sip.so','params','options','destroy','sort','filters','status','request\x20sent','json','Reload','index','like','send','create','end','get','/etc/asterisk/sip_xcally_registers.conf','join','nolimit','render','rawAttributes','readFileSync','createdAt','message','update','merge','/etc/asterisk/sip_xcally_trunks.conf','root','limit','updatedAt','sendStatus','code','map','stack','catch','utf8','client','where'];(function(_0x3312a2,_0x242542){const _0x10bc32=function(_0x24aa7c){while(--_0x24aa7c){_0x3312a2['push'](_0x3312a2['shift']());}};_0x10bc32(++_0x242542);}(a643_0x2425,0x16d));const a643_0x10bc=function(_0x3312a2,_0x242542){_0x3312a2=_0x3312a2-0x0;let _0x10bc32=a643_0x2425[_0x3312a2];return _0x10bc32;};const _0xdda70b=a643_0x10bc;'use strict';const path=require(_0xdda70b('0x1f')),ejs=require('ejs'),fs=require('fs'),_=require(_0xdda70b('0x1c')),qs=require('../../components/parsers/qs'),logger=require(_0xdda70b('0x20'))(_0xdda70b('0x1e')),config=require(_0xdda70b('0x24')),db=require(_0xdda70b('0x27'))['db'],{Op}=require(_0xdda70b('0x2f')),jayson=require('jayson/promise'),client=jayson[_0xdda70b('0x58')][_0xdda70b('0x3')]({'port':0x232a});function respondWithRpcPromise(_0x24aa7c,_0x579a0c,_0x1d0e00,_0x3f98aa){return new Promise(function(_0x454ef8,_0x44be05){const _0x34173d=a643_0x10bc,_0x4f52cc=_0x3f98aa||client;return _0x4f52cc[_0x34173d('0x25')](_0x24aa7c,_0x1d0e00)[_0x34173d('0xa')](function(_0x3d19e6){const _0x170009=_0x34173d;logger['info'](_0x170009('0x12'),_0x579a0c,_0x170009('0x3b')),logger['debug']('Trunk,\x20%s,\x20%s,\x20%s',_0x579a0c,_0x170009('0x3b'),JSON[_0x170009('0x0')](_0x3d19e6));if(_0x3d19e6[_0x170009('0x2')]){if(_0x3d19e6[_0x170009('0x2')][_0x170009('0x53')]===0x1f4)return logger[_0x170009('0x2')](_0x170009('0x12'),_0x579a0c,_0x3d19e6[_0x170009('0x2')][_0x170009('0x4b')]),_0x44be05(_0x3d19e6['error']['message']);return logger[_0x170009('0x2')](_0x170009('0x12'),_0x579a0c,_0x3d19e6[_0x170009('0x2')][_0x170009('0x4b')]),_0x454ef8(_0x3d19e6[_0x170009('0x2')]['message']);}else logger[_0x170009('0x10')](_0x170009('0x12'),_0x579a0c,'request\x20sent'),_0x454ef8(_0x3d19e6[_0x170009('0x1a')]['message']);})['catch'](function(_0x1cc8fd){const _0x40d87f=_0x34173d;logger[_0x40d87f('0x2')]('Trunk,\x20%s,\x20%s',_0x579a0c,_0x1cc8fd),_0x44be05(_0x1cc8fd);});});}function respondWithResult(_0x1fe725,_0x52ef68){return _0x52ef68=_0x52ef68||0xc8,function(_0x315ffd){const _0x18b586=a643_0x10bc;if(_0x315ffd)return _0x1fe725[_0x18b586('0x3a')](_0x52ef68)[_0x18b586('0x3c')](_0x315ffd);};}function respondWithFilteredResult(_0xf61cdd,_0x444fb9){return function(_0x455bbc){const _0x1cd3b1=a643_0x10bc;if(_0x455bbc){const _0xa912a3=_0x455bbc[_0x1cd3b1('0x15')],_0x4b20ce=_0x444fb9[_0x1cd3b1('0x19')];let _0x3f14c3=_0x444fb9['offset']+_0x444fb9[_0x1cd3b1('0x50')],_0x468b60;return _0x3f14c3>=_0xa912a3?(_0x3f14c3=_0xa912a3,_0x468b60=0xc8):_0x468b60=0xce,_0xf61cdd[_0x1cd3b1('0x3a')](_0x468b60),_0xf61cdd[_0x1cd3b1('0x23')](_0x1cd3b1('0x7'),_0x4b20ce+'-'+_0x3f14c3+'/'+_0xa912a3)[_0x1cd3b1('0x3c')](_0x455bbc);}return null;};}function saveUpdates(_0x4e202c){return function(_0x1d5801){const _0x5612b4=a643_0x10bc;if(_0x1d5801)return _0x1d5801[_0x5612b4('0x4c')](_0x4e202c)[_0x5612b4('0xa')](function(_0x3bc260){return _0x3bc260;});return null;};}function removeEntity(_0xa79fe2){return function(_0x75e6ea){const _0x5a532e=a643_0x10bc;if(_0x75e6ea)return _0x75e6ea[_0x5a532e('0x37')]()[_0x5a532e('0xa')](function(){const _0x42699d=_0x5a532e,_0x11a5f8=_0x75e6ea['get']({'plain':!![]}),_0x174cd7=_0x42699d('0x33');return db[_0x42699d('0x2d')][_0x42699d('0x37')]({'where':{'type':_0x174cd7,'resourceId':_0x11a5f8['id']}})[_0x42699d('0xa')](function(){return _0x75e6ea;});})[_0x5a532e('0xa')](function(){const _0x240203=_0x5a532e;_0xa79fe2[_0x240203('0x3a')](0xcc)[_0x240203('0x42')]();});};}function handleEntityNotFound(_0x25579e){return function(_0x117fb4){const _0x146bf2=a643_0x10bc;return!_0x117fb4&&_0x25579e[_0x146bf2('0x52')](0x194),_0x117fb4;};}function handleError(_0x26b4ff,_0x56d5ee){return _0x56d5ee=_0x56d5ee||0x1f4,function(_0x16726f){const _0x1d1098=a643_0x10bc;logger[_0x1d1098('0x2')](_0x16726f[_0x1d1098('0x55')]),_0x16726f[_0x1d1098('0x13')]&&delete _0x16726f[_0x1d1098('0x13')],_0x26b4ff[_0x1d1098('0x3a')](_0x56d5ee)[_0x1d1098('0x40')](_0x16726f);};}exports[_0xdda70b('0x3e')]=function(_0x57387c,_0x5dc0d0){const _0x2f448e=_0xdda70b;let _0x5595a6={};const _0x8695e3={},_0x3f8c96={'count':0x0,'rows':[]},_0x37e68d=_[_0x2f448e('0x54')](db[_0x2f448e('0x21')]['rawAttributes'],function(_0x3248f5){const _0x301f1d=_0x2f448e;return{'name':_0x3248f5[_0x301f1d('0xb')],'type':_0x3248f5[_0x301f1d('0x9')]['key']};});_0x8695e3['model']=_[_0x2f448e('0x54')](_0x37e68d,_0x2f448e('0x13')),_0x8695e3[_0x2f448e('0x4')]=_[_0x2f448e('0x18')](_0x57387c[_0x2f448e('0x4')]),_0x8695e3[_0x2f448e('0x39')]=_['intersection'](_0x8695e3['model'],_0x8695e3['query']),_0x5595a6['attributes']=_[_0x2f448e('0x8')](_0x8695e3[_0x2f448e('0xe')],qs[_0x2f448e('0x11')](_0x57387c[_0x2f448e('0x4')][_0x2f448e('0x11')])),_0x5595a6[_0x2f448e('0x1d')]=_0x5595a6[_0x2f448e('0x1d')]['length']?_0x5595a6[_0x2f448e('0x1d')]:_0x8695e3[_0x2f448e('0xe')];typeof _0x57387c[_0x2f448e('0x4')][_0x2f448e('0x46')]===_0x2f448e('0x2a')&&(_0x5595a6[_0x2f448e('0x50')]=qs[_0x2f448e('0x50')](_0x57387c['query']['limit']),_0x5595a6[_0x2f448e('0x19')]=qs[_0x2f448e('0x19')](_0x57387c[_0x2f448e('0x4')][_0x2f448e('0x19')]));_0x5595a6[_0x2f448e('0x26')]=qs[_0x2f448e('0x38')](_0x57387c[_0x2f448e('0x4')][_0x2f448e('0x38')]),_0x5595a6[_0x2f448e('0x59')]=qs[_0x2f448e('0x39')](_[_0x2f448e('0x16')](_0x57387c[_0x2f448e('0x4')],_0x8695e3[_0x2f448e('0x39')]),_0x37e68d);_0x57387c[_0x2f448e('0x4')][_0x2f448e('0x5a')]&&(_0x5595a6[_0x2f448e('0x59')]=_[_0x2f448e('0x4d')](_0x5595a6[_0x2f448e('0x59')],{[Op['or']]:_[_0x2f448e('0x54')](_0x37e68d,function(_0x18855e){const _0x3e24c9=_0x2f448e;if(_0x18855e[_0x3e24c9('0x9')]!==_0x3e24c9('0x2c')){const _0x15ba49={};return _0x15ba49[_0x18855e[_0x3e24c9('0x13')]]={[Op[_0x3e24c9('0x3f')]]:'%'+_0x57387c[_0x3e24c9('0x4')]['filter']+'%'},_0x15ba49;}})}));_0x5595a6=_[_0x2f448e('0x4d')]({},_0x5595a6,_0x57387c[_0x2f448e('0x36')]);const _0x3e4d8c={'where':_0x5595a6[_0x2f448e('0x59')]};return db[_0x2f448e('0x21')][_0x2f448e('0x15')](_0x3e4d8c)[_0x2f448e('0xa')](function(_0x2f1042){const _0x2a7687=_0x2f448e;return _0x3f8c96[_0x2a7687('0x15')]=_0x2f1042,_0x57387c[_0x2a7687('0x4')]['includeAll']&&(_0x5595a6[_0x2a7687('0x29')]=[{'all':!![]}]),db[_0x2a7687('0x21')]['findAll'](_0x5595a6);})[_0x2f448e('0xa')](function(_0x56b74a){return _0x3f8c96['rows']=_0x56b74a,_0x3f8c96;})[_0x2f448e('0xa')](respondWithFilteredResult(_0x5dc0d0,_0x5595a6))[_0x2f448e('0x56')](handleError(_0x5dc0d0,null));},exports['show']=function(_0x23117e,_0x5d3a88){const _0x1bf2a4=_0xdda70b;let _0x4d08c5={'raw':![],'where':{'id':_0x23117e[_0x1bf2a4('0x35')]['id']}};const _0x27bf59={};return _0x27bf59[_0x1bf2a4('0xe')]=_[_0x1bf2a4('0x18')](db[_0x1bf2a4('0x21')][_0x1bf2a4('0x48')]),_0x27bf59[_0x1bf2a4('0x4')]=_[_0x1bf2a4('0x18')](_0x23117e[_0x1bf2a4('0x4')]),_0x27bf59[_0x1bf2a4('0x39')]=_[_0x1bf2a4('0x8')](_0x27bf59[_0x1bf2a4('0xe')],_0x27bf59[_0x1bf2a4('0x4')]),_0x4d08c5['attributes']=_[_0x1bf2a4('0x8')](_0x27bf59[_0x1bf2a4('0xe')],qs[_0x1bf2a4('0x11')](_0x23117e[_0x1bf2a4('0x4')][_0x1bf2a4('0x11')])),_0x4d08c5[_0x1bf2a4('0x1d')]=_0x4d08c5[_0x1bf2a4('0x1d')][_0x1bf2a4('0x6')]?_0x4d08c5[_0x1bf2a4('0x1d')]:_0x27bf59[_0x1bf2a4('0xe')],_0x23117e['query'][_0x1bf2a4('0x28')]&&(_0x4d08c5['include']=[{'all':!![]}]),_0x4d08c5=_[_0x1bf2a4('0x4d')]({},_0x4d08c5,_0x23117e['options']),db['Trunk'][_0x1bf2a4('0x1')](_0x4d08c5)['then'](handleEntityNotFound(_0x5d3a88,null))[_0x1bf2a4('0xa')](respondWithResult(_0x5d3a88,null))[_0x1bf2a4('0x56')](handleError(_0x5d3a88,null));},exports['clone']=function(_0x41a928,_0x6d2d9e){const _0x323b99=_0xdda70b;let _0x19e235={'where':{'id':_0x41a928[_0x323b99('0x35')]['id']}};const _0x381950={};return _0x381950[_0x323b99('0xe')]=_[_0x323b99('0x18')](db['Trunk'][_0x323b99('0x48')]),_0x19e235[_0x323b99('0x1d')]=_['intersection'](_0x381950['model'],qs['fields'](_0x41a928[_0x323b99('0x4')]['fields'])),_0x19e235[_0x323b99('0x1d')]=_0x19e235[_0x323b99('0x1d')][_0x323b99('0x6')]?_0x19e235['attributes']:_0x381950[_0x323b99('0xe')],_0x41a928[_0x323b99('0x4')][_0x323b99('0x28')]&&(_0x19e235['include']=[{'all':!![]}]),_0x19e235=_[_0x323b99('0x4d')]({},_0x19e235,_0x41a928['options']),db[_0x323b99('0x21')][_0x323b99('0x1')](_0x19e235)[_0x323b99('0xa')](handleEntityNotFound(_0x6d2d9e,null))['then'](function(_0x3ef8fe){const _0x158a3d=_0x323b99;if(_0x3ef8fe){let _0x3da9da=_0x3ef8fe[_0x158a3d('0x43')]({'plain':!![]});return _0x3da9da=qs[_0x158a3d('0x17')](_0x3da9da,['id',_0x158a3d('0x4a'),_0x158a3d('0x51')]),_0x41a928[_0x158a3d('0x30')]=_[_0x158a3d('0x17')](_0x41a928[_0x158a3d('0x30')],['id',_0x158a3d('0x4a'),_0x158a3d('0x51')]),db[_0x158a3d('0x21')][_0x158a3d('0x41')](_[_0x158a3d('0x4d')](_0x3da9da,_0x41a928[_0x158a3d('0x30')]),{'include':_0x41a928[_0x158a3d('0x4')]['includeAll']?[{'all':!![]}]:undefined})['then'](function(_0x4b2341){const _0x505f06=_0x158a3d,_0x4c2aec=_0x41a928[_0x505f06('0xd')][_0x505f06('0x43')]({'plain':!![]});if(!_0x4c2aec)throw new Error(_0x505f06('0xc'));if(_0x4c2aec[_0x505f06('0x32')]==='user'){const _0x1919ea=_0x4b2341['get']({'plain':!![]}),_0x466630='Trunks';return db[_0x505f06('0x2e')]['findOne']({'where':{'name':_0x466630,'userProfileId':_0x4c2aec['userProfileId']},'raw':!![]})[_0x505f06('0xa')](function(_0x221a0f){const _0x569277=_0x505f06;return _0x221a0f&&_0x221a0f[_0x569277('0x22')]===0x0?db[_0x569277('0x2d')][_0x569277('0x41')]({'name':_0x1919ea[_0x569277('0x13')],'resourceId':_0x1919ea['id'],'type':_0x221a0f['name'],'sectionId':_0x221a0f['id']},{})[_0x569277('0xa')](function(){return _0x4b2341;}):_0x4b2341;})[_0x505f06('0x56')](function(_0x36adc2){const _0x32bad3=_0x505f06;logger[_0x32bad3('0x2')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x36adc2);throw _0x36adc2;});}return _0x4b2341;});}})[_0x323b99('0xa')](respondWithResult(_0x6d2d9e,0xc9))[_0x323b99('0x56')](handleError(_0x6d2d9e,null));},exports[_0xdda70b('0x41')]=function(_0x5ca5bc,_0x25fa95){const _0x565d3f=_0xdda70b;let _0x2e747f;return db[_0x565d3f('0x21')][_0x565d3f('0x41')](_0x5ca5bc['body'],{'raw':!![]})[_0x565d3f('0xa')](function(_0x2bbec8){const _0x3bb703=_0x565d3f;return _0x2e747f=_0x2bbec8,db[_0x3bb703('0x21')][_0x3bb703('0x31')]({'raw':!![]});})['then'](function(_0x2c9216){const _0x3eef0d=_0x565d3f,_0x66c446=fs[_0x3eef0d('0x49')](path[_0x3eef0d('0x45')](config[_0x3eef0d('0x4f')],_0x3eef0d('0x2b')),'utf8'),_0x9090e2=fs['readFileSync'](path[_0x3eef0d('0x45')](config[_0x3eef0d('0x4f')],_0x3eef0d('0x1b')),'utf8'),_0x45ee66=ejs[_0x3eef0d('0x47')](_0x66c446,{'trunks':_0x2c9216||[]});fs[_0x3eef0d('0x5')](_0x3eef0d('0x4e'),_0x45ee66);if(_0x2e747f[_0x3eef0d('0x14')]){const _0x2850dc=ejs[_0x3eef0d('0x47')](_0x9090e2,{'trunks':_0x2c9216||[]});fs['writeFileSync'](_0x3eef0d('0x44'),_0x2850dc);}})[_0x565d3f('0xa')](function(){const _0x411d49=_0x565d3f;return respondWithRpcPromise(_0x411d49('0x3d'),_0x411d49('0x41'),{'module':'chan_sip.so'});})['then'](function(){const _0x34eed4=_0x565d3f,_0x1e3872=_0x5ca5bc[_0x34eed4('0xd')][_0x34eed4('0x43')]({'plain':!![]});if(!_0x1e3872)throw new Error(_0x34eed4('0xc'));if(_0x1e3872['role']===_0x34eed4('0xd')){const _0x466fda=_0x2e747f[_0x34eed4('0x43')]({'plain':!![]});return db[_0x34eed4('0x2e')]['findOne']({'where':{'name':_0x34eed4('0x33'),'userProfileId':_0x1e3872[_0x34eed4('0xf')]},'raw':!![]})['then'](function(_0x1b1570){const _0x59a926=_0x34eed4;return _0x1b1570&&_0x1b1570[_0x59a926('0x22')]===0x0?db[_0x59a926('0x2d')]['create']({'name':_0x466fda[_0x59a926('0x13')],'resourceId':_0x466fda['id'],'type':_0x1b1570[_0x59a926('0x13')],'sectionId':_0x1b1570['id']},{})[_0x59a926('0xa')](function(){return _0x2e747f;}):_0x2e747f;})[_0x34eed4('0x56')](function(_0x44acd3){const _0x9c5a69=_0x34eed4;logger[_0x9c5a69('0x2')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x44acd3);throw _0x44acd3;});}return _0x2e747f;})[_0x565d3f('0xa')](respondWithResult(_0x25fa95,0xc9))[_0x565d3f('0x56')](handleError(_0x25fa95,null));},exports[_0xdda70b('0x4c')]=function(_0x4caea0,_0x5c8a5e){const _0x84460e=_0xdda70b;let _0x2835d3;return db[_0x84460e('0x21')][_0x84460e('0x1')]({'where':{'id':_0x4caea0['params']['id']}})[_0x84460e('0xa')](handleEntityNotFound(_0x5c8a5e,null))[_0x84460e('0xa')](saveUpdates(_0x4caea0[_0x84460e('0x30')],null))[_0x84460e('0xa')](function(_0x29ce0e){const _0x484fba=_0x84460e;if(_0x29ce0e)return _0x2835d3=_0x29ce0e,db[_0x484fba('0x21')]['findAll']({'raw':!![]});})['then'](function(_0x235eeb){const _0x4fbab9=_0x84460e;if(_0x235eeb){const _0x9d455=fs[_0x4fbab9('0x49')](path['join'](config[_0x4fbab9('0x4f')],'files/templates/trunk.ejs'),_0x4fbab9('0x57')),_0x47cd27=fs[_0x4fbab9('0x49')](path[_0x4fbab9('0x45')](config[_0x4fbab9('0x4f')],_0x4fbab9('0x1b')),_0x4fbab9('0x57')),_0x4ef6be=ejs[_0x4fbab9('0x47')](_0x9d455,{'trunks':_0x235eeb||[]});fs[_0x4fbab9('0x5')](_0x4fbab9('0x4e'),_0x4ef6be);const _0x5b3977=ejs[_0x4fbab9('0x47')](_0x47cd27,{'trunks':_0x235eeb||[]});return fs['writeFileSync']('/etc/asterisk/sip_xcally_registers.conf',_0x5b3977),respondWithRpcPromise(_0x4fbab9('0x3d'),_0x4fbab9('0x4c'),{'module':_0x4fbab9('0x34')});}return null;})[_0x84460e('0xa')](function(_0x3ddb7c){if(_0x3ddb7c)return _0x2835d3;})['then'](respondWithResult(_0x5c8a5e,null))[_0x84460e('0x56')](handleError(_0x5c8a5e,null));},exports[_0xdda70b('0x37')]=function(_0x468b78,_0x38929d){const _0x339929=_0xdda70b;return db[_0x339929('0x21')][_0x339929('0x1')]({'where':{'id':_0x468b78[_0x339929('0x35')]['id']}})['then'](handleEntityNotFound(_0x38929d,null))[_0x339929('0xa')](removeEntity(_0x38929d,null))['then'](function(){const _0x10b154=_0x339929;return db[_0x10b154('0x21')][_0x10b154('0x31')]({'raw':!![]});})[_0x339929('0xa')](function(_0x423cbc){const _0x94b8cd=_0x339929,_0x21e4b7=fs[_0x94b8cd('0x49')](path[_0x94b8cd('0x45')](config[_0x94b8cd('0x4f')],_0x94b8cd('0x2b')),_0x94b8cd('0x57')),_0x31c659=fs[_0x94b8cd('0x49')](path[_0x94b8cd('0x45')](config[_0x94b8cd('0x4f')],_0x94b8cd('0x1b')),_0x94b8cd('0x57')),_0x5d4ba4=ejs[_0x94b8cd('0x47')](_0x21e4b7,{'trunks':_0x423cbc}),_0x33021b=ejs[_0x94b8cd('0x47')](_0x31c659,{'trunks':_0x423cbc});return fs[_0x94b8cd('0x5')]('/etc/asterisk/sip_xcally_trunks.conf',_0x5d4ba4),fs[_0x94b8cd('0x5')](_0x94b8cd('0x44'),_0x33021b),respondWithRpcPromise(_0x94b8cd('0x3d'),'destroy',{'module':_0x94b8cd('0x34')});})[_0x339929('0x56')](handleError(_0x38929d,null));};
\ No newline at end of file
+const a643_0x3c97=['path','end','files/templates/registry.ejs','length','role','../../config/logger','destroy','../../config/environment','ejs','registry','clone','set','createdAt','name','error','index','count','Trunk','fields','json','Reload','Trunks','/etc/asterisk/sip_xcally_registers.conf','Unable\x20to\x20retrieve\x20the\x20current\x20user','autoAssociation','get','UserProfileResource','client','http','send','order','api','readFileSync','UserProfileSection','model','fieldName','body','info','lodash','where','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','message','updatedAt','merge','limit','create','sequelize','/etc/asterisk/sip_xcally_trunks.conf','catch','findOne','filter','update','chan_sip.so','../../mysqldb','include','omit','type','rows','params','request','includeAll','intersection','query','undefined','keys','files/templates/trunk.ejs','join','root','render','result','nolimit','status','rawAttributes','utf8','attributes','sort','Trunk,\x20%s,\x20%s','request\x20sent','userProfileId','VIRTUAL','then','pick','filters','../../components/parsers/qs','stringify','offset','writeFileSync','jayson/promise','sendStatus','findAll','user','debug','map','show'];(function(_0x20a0c8,_0x3c97c8){const _0x51a205=function(_0x3718f6){while(--_0x3718f6){_0x20a0c8['push'](_0x20a0c8['shift']());}};_0x51a205(++_0x3c97c8);}(a643_0x3c97,0x7a));const a643_0x51a2=function(_0x20a0c8,_0x3c97c8){_0x20a0c8=_0x20a0c8-0x0;let _0x51a205=a643_0x3c97[_0x20a0c8];return _0x51a205;};const _0x2901ff=a643_0x51a2;'use strict';const path=require(_0x2901ff('0x42')),ejs=require(_0x2901ff('0x4a')),fs=require('fs'),_=require(_0x2901ff('0xa')),qs=require(_0x2901ff('0x37')),logger=require(_0x2901ff('0x47'))(_0x2901ff('0x3')),config=require(_0x2901ff('0x49')),db=require(_0x2901ff('0x19'))['db'],{Op}=require(_0x2901ff('0x12')),jayson=require(_0x2901ff('0x3b')),client=jayson[_0x2901ff('0x5d')][_0x2901ff('0x0')]({'port':0x232a});function respondWithRpcPromise(_0x3718f6,_0x4c2e6a,_0x437abb,_0x564b12){return new Promise(function(_0xa89e46,_0x562652){const _0x107b8d=a643_0x51a2,_0x442354=_0x564b12||client;return _0x442354[_0x107b8d('0x1f')](_0x3718f6,_0x437abb)['then'](function(_0xb412a0){const _0x2af234=_0x107b8d;logger[_0x2af234('0x9')](_0x2af234('0x30'),_0x4c2e6a,_0x2af234('0x31')),logger[_0x2af234('0x3f')]('Trunk,\x20%s,\x20%s,\x20%s',_0x4c2e6a,'request\x20sent',JSON[_0x2af234('0x38')](_0xb412a0));if(_0xb412a0['error']){if(_0xb412a0[_0x2af234('0x50')]['code']===0x1f4)return logger[_0x2af234('0x50')](_0x2af234('0x30'),_0x4c2e6a,_0xb412a0[_0x2af234('0x50')][_0x2af234('0xd')]),_0x562652(_0xb412a0[_0x2af234('0x50')][_0x2af234('0xd')]);return logger[_0x2af234('0x50')]('Trunk,\x20%s,\x20%s',_0x4c2e6a,_0xb412a0['error'][_0x2af234('0xd')]),_0xa89e46(_0xb412a0[_0x2af234('0x50')][_0x2af234('0xd')]);}else logger[_0x2af234('0x9')](_0x2af234('0x30'),_0x4c2e6a,'request\x20sent'),_0xa89e46(_0xb412a0[_0x2af234('0x29')]['message']);})[_0x107b8d('0x14')](function(_0x5ec491){const _0xd40f2b=_0x107b8d;logger['error'](_0xd40f2b('0x30'),_0x4c2e6a,_0x5ec491),_0x562652(_0x5ec491);});});}function respondWithResult(_0x250d15,_0x3ae754){return _0x3ae754=_0x3ae754||0xc8,function(_0xae7cc3){const _0x4581fb=a643_0x51a2;if(_0xae7cc3)return _0x250d15[_0x4581fb('0x2b')](_0x3ae754)[_0x4581fb('0x55')](_0xae7cc3);};}function respondWithFilteredResult(_0x15bc79,_0x181074){return function(_0x2b60a2){const _0x223bed=a643_0x51a2;if(_0x2b60a2){const _0x443630=_0x2b60a2[_0x223bed('0x52')],_0x4e1ad4=_0x181074[_0x223bed('0x39')];let _0xc38000=_0x181074[_0x223bed('0x39')]+_0x181074['limit'],_0x1497dd;return _0xc38000>=_0x443630?(_0xc38000=_0x443630,_0x1497dd=0xc8):_0x1497dd=0xce,_0x15bc79[_0x223bed('0x2b')](_0x1497dd),_0x15bc79[_0x223bed('0x4d')]('Content-Range',_0x4e1ad4+'-'+_0xc38000+'/'+_0x443630)[_0x223bed('0x55')](_0x2b60a2);}return null;};}function saveUpdates(_0x10756f){return function(_0x23315f){const _0x4438f9=a643_0x51a2;if(_0x23315f)return _0x23315f[_0x4438f9('0x17')](_0x10756f)[_0x4438f9('0x34')](function(_0x5b90ed){return _0x5b90ed;});return null;};}function removeEntity(_0x48ce3d){return function(_0x338f39){const _0x29df75=a643_0x51a2;if(_0x338f39)return _0x338f39[_0x29df75('0x48')]()[_0x29df75('0x34')](function(){const _0x17e8bc=_0x29df75,_0x24cead=_0x338f39[_0x17e8bc('0x5b')]({'plain':!![]}),_0x49622e=_0x17e8bc('0x57');return db[_0x17e8bc('0x5c')][_0x17e8bc('0x48')]({'where':{'type':_0x49622e,'resourceId':_0x24cead['id']}})['then'](function(){return _0x338f39;});})[_0x29df75('0x34')](function(){const _0x46e5f1=_0x29df75;_0x48ce3d[_0x46e5f1('0x2b')](0xcc)[_0x46e5f1('0x43')]();});};}function handleEntityNotFound(_0x38f489){return function(_0x22fb77){const _0x2ad6ef=a643_0x51a2;return!_0x22fb77&&_0x38f489[_0x2ad6ef('0x3c')](0x194),_0x22fb77;};}function handleError(_0x58e1a6,_0x3b96ed){return _0x3b96ed=_0x3b96ed||0x1f4,function(_0x3e9354){const _0x46bf15=a643_0x51a2;logger[_0x46bf15('0x50')](_0x3e9354['stack']),_0x3e9354['name']&&delete _0x3e9354['name'],_0x58e1a6[_0x46bf15('0x2b')](_0x3b96ed)[_0x46bf15('0x1')](_0x3e9354);};}exports[_0x2901ff('0x51')]=function(_0x4378a2,_0x49521b){const _0x490b6f=_0x2901ff;let _0x38f245={};const _0x496f6e={},_0x30783f={'count':0x0,'rows':[]},_0x2efcd6=_[_0x490b6f('0x40')](db[_0x490b6f('0x53')][_0x490b6f('0x2c')],function(_0x5c614c){const _0x4903a5=_0x490b6f;return{'name':_0x5c614c[_0x4903a5('0x7')],'type':_0x5c614c[_0x4903a5('0x1c')]['key']};});_0x496f6e[_0x490b6f('0x6')]=_[_0x490b6f('0x40')](_0x2efcd6,_0x490b6f('0x4f')),_0x496f6e[_0x490b6f('0x22')]=_[_0x490b6f('0x24')](_0x4378a2[_0x490b6f('0x22')]),_0x496f6e['filters']=_[_0x490b6f('0x21')](_0x496f6e[_0x490b6f('0x6')],_0x496f6e[_0x490b6f('0x22')]),_0x38f245[_0x490b6f('0x2e')]=_['intersection'](_0x496f6e[_0x490b6f('0x6')],qs[_0x490b6f('0x54')](_0x4378a2['query'][_0x490b6f('0x54')])),_0x38f245['attributes']=_0x38f245[_0x490b6f('0x2e')]['length']?_0x38f245[_0x490b6f('0x2e')]:_0x496f6e[_0x490b6f('0x6')];typeof _0x4378a2[_0x490b6f('0x22')][_0x490b6f('0x2a')]===_0x490b6f('0x23')&&(_0x38f245[_0x490b6f('0x10')]=qs['limit'](_0x4378a2[_0x490b6f('0x22')]['limit']),_0x38f245[_0x490b6f('0x39')]=qs[_0x490b6f('0x39')](_0x4378a2[_0x490b6f('0x22')][_0x490b6f('0x39')]));_0x38f245[_0x490b6f('0x2')]=qs['sort'](_0x4378a2[_0x490b6f('0x22')][_0x490b6f('0x2f')]),_0x38f245[_0x490b6f('0xb')]=qs[_0x490b6f('0x36')](_[_0x490b6f('0x35')](_0x4378a2[_0x490b6f('0x22')],_0x496f6e[_0x490b6f('0x36')]),_0x2efcd6);_0x4378a2['query']['filter']&&(_0x38f245[_0x490b6f('0xb')]=_['merge'](_0x38f245['where'],{[Op['or']]:_['map'](_0x2efcd6,function(_0xe70b44){const _0x1e9757=_0x490b6f;if(_0xe70b44[_0x1e9757('0x1c')]!==_0x1e9757('0x33')){const _0x7399e0={};return _0x7399e0[_0xe70b44[_0x1e9757('0x4f')]]={[Op['like']]:'%'+_0x4378a2[_0x1e9757('0x22')][_0x1e9757('0x16')]+'%'},_0x7399e0;}})}));_0x38f245=_[_0x490b6f('0xf')]({},_0x38f245,_0x4378a2['options']);const _0x200203={'where':_0x38f245[_0x490b6f('0xb')]};return db[_0x490b6f('0x53')][_0x490b6f('0x52')](_0x200203)[_0x490b6f('0x34')](function(_0x33121f){const _0x16cf58=_0x490b6f;return _0x30783f[_0x16cf58('0x52')]=_0x33121f,_0x4378a2[_0x16cf58('0x22')][_0x16cf58('0x20')]&&(_0x38f245[_0x16cf58('0x1a')]=[{'all':!![]}]),db[_0x16cf58('0x53')][_0x16cf58('0x3d')](_0x38f245);})['then'](function(_0x420e11){const _0x415bcb=_0x490b6f;return _0x30783f[_0x415bcb('0x1d')]=_0x420e11,_0x30783f;})[_0x490b6f('0x34')](respondWithFilteredResult(_0x49521b,_0x38f245))[_0x490b6f('0x14')](handleError(_0x49521b,null));},exports[_0x2901ff('0x41')]=function(_0x5f2dc6,_0x1b6814){const _0x115e00=_0x2901ff;let _0x385e2c={'raw':![],'where':{'id':_0x5f2dc6[_0x115e00('0x1e')]['id']}};const _0x127e5a={};return _0x127e5a[_0x115e00('0x6')]=_['keys'](db[_0x115e00('0x53')][_0x115e00('0x2c')]),_0x127e5a[_0x115e00('0x22')]=_['keys'](_0x5f2dc6[_0x115e00('0x22')]),_0x127e5a[_0x115e00('0x36')]=_['intersection'](_0x127e5a[_0x115e00('0x6')],_0x127e5a[_0x115e00('0x22')]),_0x385e2c['attributes']=_['intersection'](_0x127e5a['model'],qs['fields'](_0x5f2dc6[_0x115e00('0x22')][_0x115e00('0x54')])),_0x385e2c[_0x115e00('0x2e')]=_0x385e2c[_0x115e00('0x2e')][_0x115e00('0x45')]?_0x385e2c[_0x115e00('0x2e')]:_0x127e5a[_0x115e00('0x6')],_0x5f2dc6[_0x115e00('0x22')][_0x115e00('0x20')]&&(_0x385e2c[_0x115e00('0x1a')]=[{'all':!![]}]),_0x385e2c=_['merge']({},_0x385e2c,_0x5f2dc6['options']),db[_0x115e00('0x53')][_0x115e00('0x15')](_0x385e2c)[_0x115e00('0x34')](handleEntityNotFound(_0x1b6814,null))[_0x115e00('0x34')](respondWithResult(_0x1b6814,null))['catch'](handleError(_0x1b6814,null));},exports[_0x2901ff('0x4c')]=function(_0x39a1e4,_0x57e2f8){const _0x315b79=_0x2901ff;let _0x36b8b8={'where':{'id':_0x39a1e4['params']['id']}};const _0x7a9888={};return _0x7a9888[_0x315b79('0x6')]=_[_0x315b79('0x24')](db[_0x315b79('0x53')][_0x315b79('0x2c')]),_0x36b8b8[_0x315b79('0x2e')]=_[_0x315b79('0x21')](_0x7a9888['model'],qs[_0x315b79('0x54')](_0x39a1e4['query']['fields'])),_0x36b8b8[_0x315b79('0x2e')]=_0x36b8b8['attributes'][_0x315b79('0x45')]?_0x36b8b8[_0x315b79('0x2e')]:_0x7a9888['model'],_0x39a1e4[_0x315b79('0x22')]['includeAll']&&(_0x36b8b8[_0x315b79('0x1a')]=[{'all':!![]}]),_0x36b8b8=_[_0x315b79('0xf')]({},_0x36b8b8,_0x39a1e4['options']),db[_0x315b79('0x53')][_0x315b79('0x15')](_0x36b8b8)[_0x315b79('0x34')](handleEntityNotFound(_0x57e2f8,null))['then'](function(_0x9a3571){const _0x235fe0=_0x315b79;if(_0x9a3571){let _0x49ffe8=_0x9a3571[_0x235fe0('0x5b')]({'plain':!![]});return _0x49ffe8=qs['omit'](_0x49ffe8,['id',_0x235fe0('0x4e'),_0x235fe0('0xe')]),_0x39a1e4[_0x235fe0('0x8')]=_[_0x235fe0('0x1b')](_0x39a1e4[_0x235fe0('0x8')],['id',_0x235fe0('0x4e'),_0x235fe0('0xe')]),db[_0x235fe0('0x53')][_0x235fe0('0x11')](_['merge'](_0x49ffe8,_0x39a1e4[_0x235fe0('0x8')]),{'include':_0x39a1e4[_0x235fe0('0x22')][_0x235fe0('0x20')]?[{'all':!![]}]:undefined})[_0x235fe0('0x34')](function(_0x389412){const _0x481ed2=_0x235fe0,_0x1c3c1b=_0x39a1e4[_0x481ed2('0x3e')][_0x481ed2('0x5b')]({'plain':!![]});if(!_0x1c3c1b)throw new Error(_0x481ed2('0x59'));if(_0x1c3c1b[_0x481ed2('0x46')]==='user'){const _0x3e3d08=_0x389412[_0x481ed2('0x5b')]({'plain':!![]}),_0x2726e6='Trunks';return db[_0x481ed2('0x5')][_0x481ed2('0x15')]({'where':{'name':_0x2726e6,'userProfileId':_0x1c3c1b[_0x481ed2('0x32')]},'raw':!![]})['then'](function(_0x3d7323){const _0x467bbb=_0x481ed2;return _0x3d7323&&_0x3d7323[_0x467bbb('0x5a')]===0x0?db[_0x467bbb('0x5c')][_0x467bbb('0x11')]({'name':_0x3e3d08[_0x467bbb('0x4f')],'resourceId':_0x3e3d08['id'],'type':_0x3d7323[_0x467bbb('0x4f')],'sectionId':_0x3d7323['id']},{})[_0x467bbb('0x34')](function(){return _0x389412;}):_0x389412;})['catch'](function(_0x3caa9b){const _0x206496=_0x481ed2;logger[_0x206496('0x50')](_0x206496('0xc'),_0x3caa9b);throw _0x3caa9b;});}return _0x389412;});}})['then'](respondWithResult(_0x57e2f8,0xc9))['catch'](handleError(_0x57e2f8,null));},exports['create']=function(_0x49eed2,_0x4dbf01){const _0x407a9a=_0x2901ff;let _0x131788;return db['Trunk'][_0x407a9a('0x11')](_0x49eed2[_0x407a9a('0x8')],{'raw':!![]})['then'](function(_0x615c99){const _0x20e445=_0x407a9a;return _0x131788=_0x615c99,db[_0x20e445('0x53')][_0x20e445('0x3d')]({'raw':!![]});})[_0x407a9a('0x34')](function(_0x30f478){const _0x1d9e25=_0x407a9a,_0x3f1d58=fs[_0x1d9e25('0x4')](path[_0x1d9e25('0x26')](config[_0x1d9e25('0x27')],_0x1d9e25('0x25')),'utf8'),_0x131699=fs[_0x1d9e25('0x4')](path['join'](config[_0x1d9e25('0x27')],_0x1d9e25('0x44')),_0x1d9e25('0x2d')),_0x289399=ejs[_0x1d9e25('0x28')](_0x3f1d58,{'trunks':_0x30f478||[]});fs[_0x1d9e25('0x3a')](_0x1d9e25('0x13'),_0x289399);if(_0x131788[_0x1d9e25('0x4b')]){const _0x34e2c8=ejs['render'](_0x131699,{'trunks':_0x30f478||[]});fs['writeFileSync'](_0x1d9e25('0x58'),_0x34e2c8);}})['then'](function(){const _0x2a622f=_0x407a9a;return respondWithRpcPromise(_0x2a622f('0x56'),_0x2a622f('0x11'),{'module':_0x2a622f('0x18')});})[_0x407a9a('0x34')](function(){const _0x66bf7f=_0x407a9a,_0x33f309=_0x49eed2[_0x66bf7f('0x3e')]['get']({'plain':!![]});if(!_0x33f309)throw new Error(_0x66bf7f('0x59'));if(_0x33f309[_0x66bf7f('0x46')]==='user'){const _0x2a10be=_0x131788['get']({'plain':!![]});return db[_0x66bf7f('0x5')][_0x66bf7f('0x15')]({'where':{'name':_0x66bf7f('0x57'),'userProfileId':_0x33f309[_0x66bf7f('0x32')]},'raw':!![]})[_0x66bf7f('0x34')](function(_0x1604da){const _0x343f26=_0x66bf7f;return _0x1604da&&_0x1604da[_0x343f26('0x5a')]===0x0?db[_0x343f26('0x5c')]['create']({'name':_0x2a10be[_0x343f26('0x4f')],'resourceId':_0x2a10be['id'],'type':_0x1604da[_0x343f26('0x4f')],'sectionId':_0x1604da['id']},{})['then'](function(){return _0x131788;}):_0x131788;})['catch'](function(_0x38b621){const _0x158c31=_0x66bf7f;logger[_0x158c31('0x50')](_0x158c31('0xc'),_0x38b621);throw _0x38b621;});}return _0x131788;})[_0x407a9a('0x34')](respondWithResult(_0x4dbf01,0xc9))['catch'](handleError(_0x4dbf01,null));},exports[_0x2901ff('0x17')]=function(_0x17757f,_0x210ab1){const _0x39e65d=_0x2901ff;let _0x2d32c5;return db['Trunk'][_0x39e65d('0x15')]({'where':{'id':_0x17757f[_0x39e65d('0x1e')]['id']}})[_0x39e65d('0x34')](handleEntityNotFound(_0x210ab1,null))[_0x39e65d('0x34')](saveUpdates(_0x17757f[_0x39e65d('0x8')],null))['then'](function(_0x402c67){const _0x3c0f8d=_0x39e65d;if(_0x402c67)return _0x2d32c5=_0x402c67,db[_0x3c0f8d('0x53')][_0x3c0f8d('0x3d')]({'raw':!![]});})[_0x39e65d('0x34')](function(_0x414d85){const _0x46a66f=_0x39e65d;if(_0x414d85){const _0x42e255=fs[_0x46a66f('0x4')](path['join'](config[_0x46a66f('0x27')],'files/templates/trunk.ejs'),_0x46a66f('0x2d')),_0x214320=fs['readFileSync'](path[_0x46a66f('0x26')](config[_0x46a66f('0x27')],_0x46a66f('0x44')),_0x46a66f('0x2d')),_0xb49e16=ejs[_0x46a66f('0x28')](_0x42e255,{'trunks':_0x414d85||[]});fs['writeFileSync'](_0x46a66f('0x13'),_0xb49e16);const _0x6e2380=ejs[_0x46a66f('0x28')](_0x214320,{'trunks':_0x414d85||[]});return fs[_0x46a66f('0x3a')](_0x46a66f('0x58'),_0x6e2380),respondWithRpcPromise(_0x46a66f('0x56'),_0x46a66f('0x17'),{'module':_0x46a66f('0x18')});}return null;})[_0x39e65d('0x34')](function(_0x124450){if(_0x124450)return _0x2d32c5;})[_0x39e65d('0x34')](respondWithResult(_0x210ab1,null))['catch'](handleError(_0x210ab1,null));},exports[_0x2901ff('0x48')]=function(_0x37ce18,_0x50ca5d){const _0x362986=_0x2901ff;return db[_0x362986('0x53')]['findOne']({'where':{'id':_0x37ce18[_0x362986('0x1e')]['id']}})[_0x362986('0x34')](handleEntityNotFound(_0x50ca5d,null))['then'](removeEntity(_0x50ca5d,null))[_0x362986('0x34')](function(){const _0x3c9880=_0x362986;return db[_0x3c9880('0x53')][_0x3c9880('0x3d')]({'raw':!![]});})[_0x362986('0x34')](function(_0x6978d){const _0x3b16e5=_0x362986,_0x5d812c=fs[_0x3b16e5('0x4')](path[_0x3b16e5('0x26')](config[_0x3b16e5('0x27')],_0x3b16e5('0x25')),'utf8'),_0x57054c=fs[_0x3b16e5('0x4')](path[_0x3b16e5('0x26')](config['root'],'files/templates/registry.ejs'),_0x3b16e5('0x2d')),_0x5db730=ejs['render'](_0x5d812c,{'trunks':_0x6978d}),_0x3eee14=ejs[_0x3b16e5('0x28')](_0x57054c,{'trunks':_0x6978d});return fs[_0x3b16e5('0x3a')](_0x3b16e5('0x13'),_0x5db730),fs[_0x3b16e5('0x3a')](_0x3b16e5('0x58'),_0x3eee14),respondWithRpcPromise(_0x3b16e5('0x56'),_0x3b16e5('0x48'),{'module':'chan_sip.so'});})[_0x362986('0x14')](handleError(_0x50ca5d,null));};
\ No newline at end of file