Built motion from commit df3e9871f6bcc3432fec345b2f4facbd4dba8b5c. Version 3.0.0...
[motion-next.git] / server / api / trunk / trunk.controller.js
index 8e409ae..842a9c8 100644 (file)
@@ -1 +1 @@
-const a643_0x20d6=['then','query','Reload','../../config/environment','debug','findOne','../../config/logger','writeFileSync','/etc/asterisk/sip_xcally_registers.conf','count','keys','files/templates/registry.ejs','limit','UserProfileSection','end','undefined','intersection','where','destroy','attributes','status','/etc/asterisk/sip_xcally_trunks.conf','create','info','offset','rawAttributes','autoAssociation','json','user','error','createdAt','../../mysqldb','order','chan_sip.so','omit','../../components/parsers/qs','length','merge','message','nolimit','findAll','sort','Trunk','model','Trunk,\x20%s,\x20%s','rows','includeAll','like','update','clone','key','readFileSync','params','catch','role','client','root','join','get','code','type','name','http','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','send','filters','userProfileId','options','utf8','render','index','sendStatus','body','files/templates/trunk.ejs','fields','UserProfileResource','include','Trunks','map','registry','stringify','request\x20sent','updatedAt','filter'];(function(_0x587f83,_0x20d638){const _0x1f65dd=function(_0x3da1e5){while(--_0x3da1e5){_0x587f83['push'](_0x587f83['shift']());}};_0x1f65dd(++_0x20d638);}(a643_0x20d6,0xbf));const a643_0x1f65=function(_0x587f83,_0x20d638){_0x587f83=_0x587f83-0x0;let _0x1f65dd=a643_0x20d6[_0x587f83];return _0x1f65dd;};const _0xf84920=a643_0x1f65;'use strict';const path=require('path'),ejs=require('ejs'),fs=require('fs'),_=require('lodash'),qs=require(_0xf84920('0xc')),logger=require(_0xf84920('0x43'))('api'),config=require(_0xf84920('0x40')),db=require(_0xf84920('0x8'))['db'],{Op}=require('sequelize'),jayson=require('jayson/promise'),client=jayson[_0xf84920('0x20')][_0xf84920('0x27')]({'port':0x232a});function respondWithRpcPromise(_0x3da1e5,_0x5065d4,_0x17de20,_0x49dec5){return new Promise(function(_0x56dbdf,_0x443bc1){const _0x1163e1=a643_0x1f65,_0x26eec9=_0x49dec5||client;return _0x26eec9['request'](_0x3da1e5,_0x17de20)['then'](function(_0x2bf458){const _0x123771=a643_0x1f65;logger['info'](_0x123771('0x15'),_0x5065d4,'request\x20sent'),logger[_0x123771('0x41')]('Trunk,\x20%s,\x20%s,\x20%s',_0x5065d4,_0x123771('0x3a'),JSON[_0x123771('0x39')](_0x2bf458));if(_0x2bf458[_0x123771('0x6')]){if(_0x2bf458[_0x123771('0x6')][_0x123771('0x24')]===0x1f4)return logger[_0x123771('0x6')](_0x123771('0x15'),_0x5065d4,_0x2bf458[_0x123771('0x6')][_0x123771('0xf')]),_0x443bc1(_0x2bf458[_0x123771('0x6')][_0x123771('0xf')]);return logger['error'](_0x123771('0x15'),_0x5065d4,_0x2bf458[_0x123771('0x6')][_0x123771('0xf')]),_0x56dbdf(_0x2bf458[_0x123771('0x6')][_0x123771('0xf')]);}else logger[_0x123771('0x0')](_0x123771('0x15'),_0x5065d4,_0x123771('0x3a')),_0x56dbdf(_0x2bf458['result'][_0x123771('0xf')]);})[_0x1163e1('0x1e')](function(_0x2b2b6d){const _0x977ad8=_0x1163e1;logger[_0x977ad8('0x6')](_0x977ad8('0x15'),_0x5065d4,_0x2b2b6d),_0x443bc1(_0x2b2b6d);});});}function respondWithResult(_0x36ada6,_0x258cfe){return _0x258cfe=_0x258cfe||0xc8,function(_0x2d871c){const _0x135db1=a643_0x1f65;if(_0x2d871c)return _0x36ada6['status'](_0x258cfe)[_0x135db1('0x4')](_0x2d871c);};}function respondWithFilteredResult(_0x3ffd9d,_0x3e22f6){return function(_0x1013d1){const _0x2b2b54=a643_0x1f65;if(_0x1013d1){const _0x5561a1=_0x1013d1[_0x2b2b54('0x46')],_0x4cf809=_0x3e22f6['offset'];let _0x1c4f70=_0x3e22f6[_0x2b2b54('0x1')]+_0x3e22f6[_0x2b2b54('0x49')],_0x58a128;return _0x1c4f70>=_0x5561a1?(_0x1c4f70=_0x5561a1,_0x58a128=0xc8):_0x58a128=0xce,_0x3ffd9d[_0x2b2b54('0x51')](_0x58a128),_0x3ffd9d['set']('Content-Range',_0x4cf809+'-'+_0x1c4f70+'/'+_0x5561a1)[_0x2b2b54('0x4')](_0x1013d1);}return null;};}function saveUpdates(_0x3087a9){return function(_0x267803){const _0x310aeb=a643_0x1f65;if(_0x267803)return _0x267803[_0x310aeb('0x19')](_0x3087a9)[_0x310aeb('0x3d')](function(_0x3d9edd){return _0x3d9edd;});return null;};}function removeEntity(_0x32f9b9){return function(_0x4d953b){const _0x2d646d=a643_0x1f65;if(_0x4d953b)return _0x4d953b['destroy']()['then'](function(){const _0x21319b=a643_0x1f65,_0x4f1259=_0x4d953b[_0x21319b('0x23')]({'plain':!![]}),_0x8652ce='Trunks';return db[_0x21319b('0x34')]['destroy']({'where':{'type':_0x8652ce,'resourceId':_0x4f1259['id']}})['then'](function(){return _0x4d953b;});})[_0x2d646d('0x3d')](function(){const _0x19ed4f=_0x2d646d;_0x32f9b9[_0x19ed4f('0x51')](0xcc)[_0x19ed4f('0x4b')]();});};}function handleEntityNotFound(_0x2ac6fe){return function(_0x421efa){const _0x45c4fd=a643_0x1f65;return!_0x421efa&&_0x2ac6fe[_0x45c4fd('0x30')](0x194),_0x421efa;};}function handleError(_0x4958b3,_0x1bda2c){return _0x1bda2c=_0x1bda2c||0x1f4,function(_0x2218c2){const _0x4c23fe=a643_0x1f65;logger[_0x4c23fe('0x6')](_0x2218c2['stack']),_0x2218c2[_0x4c23fe('0x26')]&&delete _0x2218c2[_0x4c23fe('0x26')],_0x4958b3[_0x4c23fe('0x51')](_0x1bda2c)[_0x4c23fe('0x29')](_0x2218c2);};}exports[_0xf84920('0x2f')]=function(_0x31b417,_0xd7e268){const _0x398cac=_0xf84920;let _0x17ac1e={};const _0x3b86aa={},_0x4d3996={'count':0x0,'rows':[]},_0x35e3be=_[_0x398cac('0x37')](db['Trunk'][_0x398cac('0x2')],function(_0x271448){const _0x27f67a=_0x398cac;return{'name':_0x271448['fieldName'],'type':_0x271448[_0x27f67a('0x25')][_0x27f67a('0x1b')]};});_0x3b86aa[_0x398cac('0x14')]=_[_0x398cac('0x37')](_0x35e3be,_0x398cac('0x26')),_0x3b86aa[_0x398cac('0x3e')]=_[_0x398cac('0x47')](_0x31b417[_0x398cac('0x3e')]),_0x3b86aa['filters']=_[_0x398cac('0x4d')](_0x3b86aa['model'],_0x3b86aa['query']),_0x17ac1e[_0x398cac('0x50')]=_[_0x398cac('0x4d')](_0x3b86aa[_0x398cac('0x14')],qs[_0x398cac('0x33')](_0x31b417[_0x398cac('0x3e')][_0x398cac('0x33')])),_0x17ac1e[_0x398cac('0x50')]=_0x17ac1e[_0x398cac('0x50')]['length']?_0x17ac1e[_0x398cac('0x50')]:_0x3b86aa[_0x398cac('0x14')];typeof _0x31b417[_0x398cac('0x3e')][_0x398cac('0x10')]===_0x398cac('0x4c')&&(_0x17ac1e[_0x398cac('0x49')]=qs[_0x398cac('0x49')](_0x31b417['query'][_0x398cac('0x49')]),_0x17ac1e[_0x398cac('0x1')]=qs['offset'](_0x31b417[_0x398cac('0x3e')][_0x398cac('0x1')]));_0x17ac1e[_0x398cac('0x9')]=qs[_0x398cac('0x12')](_0x31b417[_0x398cac('0x3e')]['sort']),_0x17ac1e['where']=qs['filters'](_['pick'](_0x31b417[_0x398cac('0x3e')],_0x3b86aa[_0x398cac('0x2a')]),_0x35e3be);_0x31b417[_0x398cac('0x3e')]['filter']&&(_0x17ac1e['where']=_['merge'](_0x17ac1e[_0x398cac('0x4e')],{[Op['or']]:_[_0x398cac('0x37')](_0x35e3be,function(_0x278653){const _0x44db5c=_0x398cac;if(_0x278653[_0x44db5c('0x25')]!=='VIRTUAL'){const _0x18782f={};return _0x18782f[_0x278653[_0x44db5c('0x26')]]={[Op[_0x44db5c('0x18')]]:'%'+_0x31b417[_0x44db5c('0x3e')][_0x44db5c('0x3c')]+'%'},_0x18782f;}})}));_0x17ac1e=_[_0x398cac('0xe')]({},_0x17ac1e,_0x31b417['options']);const _0x267f96={'where':_0x17ac1e[_0x398cac('0x4e')]};return db[_0x398cac('0x13')]['count'](_0x267f96)[_0x398cac('0x3d')](function(_0x417450){const _0x5ac687=_0x398cac;return _0x4d3996['count']=_0x417450,_0x31b417[_0x5ac687('0x3e')][_0x5ac687('0x17')]&&(_0x17ac1e[_0x5ac687('0x35')]=[{'all':!![]}]),db[_0x5ac687('0x13')]['findAll'](_0x17ac1e);})['then'](function(_0x343b71){const _0x3d2e1c=_0x398cac;return _0x4d3996[_0x3d2e1c('0x16')]=_0x343b71,_0x4d3996;})[_0x398cac('0x3d')](respondWithFilteredResult(_0xd7e268,_0x17ac1e))[_0x398cac('0x1e')](handleError(_0xd7e268,null));},exports['show']=function(_0xc2fc87,_0x5874b6){const _0x4ecf96=_0xf84920;let _0x3845d7={'raw':![],'where':{'id':_0xc2fc87[_0x4ecf96('0x1d')]['id']}};const _0x306225={};return _0x306225['model']=_[_0x4ecf96('0x47')](db[_0x4ecf96('0x13')]['rawAttributes']),_0x306225[_0x4ecf96('0x3e')]=_[_0x4ecf96('0x47')](_0xc2fc87[_0x4ecf96('0x3e')]),_0x306225[_0x4ecf96('0x2a')]=_[_0x4ecf96('0x4d')](_0x306225['model'],_0x306225['query']),_0x3845d7['attributes']=_[_0x4ecf96('0x4d')](_0x306225[_0x4ecf96('0x14')],qs[_0x4ecf96('0x33')](_0xc2fc87['query'][_0x4ecf96('0x33')])),_0x3845d7[_0x4ecf96('0x50')]=_0x3845d7[_0x4ecf96('0x50')][_0x4ecf96('0xd')]?_0x3845d7[_0x4ecf96('0x50')]:_0x306225[_0x4ecf96('0x14')],_0xc2fc87[_0x4ecf96('0x3e')]['includeAll']&&(_0x3845d7[_0x4ecf96('0x35')]=[{'all':!![]}]),_0x3845d7=_['merge']({},_0x3845d7,_0xc2fc87[_0x4ecf96('0x2c')]),db[_0x4ecf96('0x13')][_0x4ecf96('0x42')](_0x3845d7)[_0x4ecf96('0x3d')](handleEntityNotFound(_0x5874b6,null))[_0x4ecf96('0x3d')](respondWithResult(_0x5874b6,null))['catch'](handleError(_0x5874b6,null));},exports[_0xf84920('0x1a')]=function(_0x52ffd9,_0x219576){const _0xed56ed=_0xf84920;let _0x5d023={'where':{'id':_0x52ffd9[_0xed56ed('0x1d')]['id']}};const _0x51e4e9={};return _0x51e4e9[_0xed56ed('0x14')]=_[_0xed56ed('0x47')](db[_0xed56ed('0x13')]['rawAttributes']),_0x5d023[_0xed56ed('0x50')]=_[_0xed56ed('0x4d')](_0x51e4e9[_0xed56ed('0x14')],qs[_0xed56ed('0x33')](_0x52ffd9[_0xed56ed('0x3e')][_0xed56ed('0x33')])),_0x5d023[_0xed56ed('0x50')]=_0x5d023[_0xed56ed('0x50')][_0xed56ed('0xd')]?_0x5d023['attributes']:_0x51e4e9['model'],_0x52ffd9[_0xed56ed('0x3e')][_0xed56ed('0x17')]&&(_0x5d023['include']=[{'all':!![]}]),_0x5d023=_['merge']({},_0x5d023,_0x52ffd9[_0xed56ed('0x2c')]),db[_0xed56ed('0x13')][_0xed56ed('0x42')](_0x5d023)['then'](handleEntityNotFound(_0x219576,null))[_0xed56ed('0x3d')](function(_0x5ed952){const _0x5c61b0=_0xed56ed;if(_0x5ed952){let _0x6fcbc8=_0x5ed952['get']({'plain':!![]});return _0x6fcbc8=qs[_0x5c61b0('0xb')](_0x6fcbc8,['id',_0x5c61b0('0x7'),_0x5c61b0('0x3b')]),_0x52ffd9['body']=_[_0x5c61b0('0xb')](_0x52ffd9[_0x5c61b0('0x31')],['id',_0x5c61b0('0x7'),_0x5c61b0('0x3b')]),db['Trunk'][_0x5c61b0('0x53')](_[_0x5c61b0('0xe')](_0x6fcbc8,_0x52ffd9[_0x5c61b0('0x31')]),{'include':_0x52ffd9[_0x5c61b0('0x3e')][_0x5c61b0('0x17')]?[{'all':!![]}]:undefined})[_0x5c61b0('0x3d')](function(_0x4c32ff){const _0x997ddc=_0x5c61b0,_0x308110=_0x52ffd9[_0x997ddc('0x5')][_0x997ddc('0x23')]({'plain':!![]});if(!_0x308110)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x308110['role']===_0x997ddc('0x5')){const _0x212eca=_0x4c32ff[_0x997ddc('0x23')]({'plain':!![]}),_0x38335a=_0x997ddc('0x36');return db[_0x997ddc('0x4a')][_0x997ddc('0x42')]({'where':{'name':_0x38335a,'userProfileId':_0x308110[_0x997ddc('0x2b')]},'raw':!![]})[_0x997ddc('0x3d')](function(_0x5b555b){const _0x18670c=_0x997ddc;return _0x5b555b&&_0x5b555b[_0x18670c('0x3')]===0x0?db[_0x18670c('0x34')]['create']({'name':_0x212eca['name'],'resourceId':_0x212eca['id'],'type':_0x5b555b[_0x18670c('0x26')],'sectionId':_0x5b555b['id']},{})[_0x18670c('0x3d')](function(){return _0x4c32ff;}):_0x4c32ff;})[_0x997ddc('0x1e')](function(_0x2d6e4a){const _0x38f7df=_0x997ddc;logger['error'](_0x38f7df('0x28'),_0x2d6e4a);throw _0x2d6e4a;});}return _0x4c32ff;});}})[_0xed56ed('0x3d')](respondWithResult(_0x219576,0xc9))[_0xed56ed('0x1e')](handleError(_0x219576,null));},exports['create']=function(_0xbeb1f8,_0x53f860){const _0x453ad0=_0xf84920;let _0x2bd0dd;return db[_0x453ad0('0x13')][_0x453ad0('0x53')](_0xbeb1f8[_0x453ad0('0x31')],{'raw':!![]})[_0x453ad0('0x3d')](function(_0x21ff28){const _0x404888=_0x453ad0;return _0x2bd0dd=_0x21ff28,db[_0x404888('0x13')][_0x404888('0x11')]({'raw':!![]});})[_0x453ad0('0x3d')](function(_0x42aecf){const _0x513edc=_0x453ad0,_0x1d5ba2=fs[_0x513edc('0x1c')](path[_0x513edc('0x22')](config[_0x513edc('0x21')],_0x513edc('0x32')),_0x513edc('0x2d')),_0x2502fb=fs[_0x513edc('0x1c')](path[_0x513edc('0x22')](config['root'],_0x513edc('0x48')),_0x513edc('0x2d')),_0x4e9ded=ejs[_0x513edc('0x2e')](_0x1d5ba2,{'trunks':_0x42aecf||[]});fs[_0x513edc('0x44')](_0x513edc('0x52'),_0x4e9ded);if(_0x2bd0dd[_0x513edc('0x38')]){const _0x44485d=ejs[_0x513edc('0x2e')](_0x2502fb,{'trunks':_0x42aecf||[]});fs['writeFileSync'](_0x513edc('0x45'),_0x44485d);}})[_0x453ad0('0x3d')](function(){const _0x34c3c5=_0x453ad0;return respondWithRpcPromise(_0x34c3c5('0x3f'),_0x34c3c5('0x53'),{'module':'chan_sip.so'});})[_0x453ad0('0x3d')](function(){const _0x1eaae8=_0x453ad0,_0x549dc7=_0xbeb1f8['user'][_0x1eaae8('0x23')]({'plain':!![]});if(!_0x549dc7)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x549dc7[_0x1eaae8('0x1f')]===_0x1eaae8('0x5')){const _0x106c25=_0x2bd0dd[_0x1eaae8('0x23')]({'plain':!![]});return db[_0x1eaae8('0x4a')][_0x1eaae8('0x42')]({'where':{'name':'Trunks','userProfileId':_0x549dc7[_0x1eaae8('0x2b')]},'raw':!![]})['then'](function(_0x425c76){const _0x3f81e8=_0x1eaae8;return _0x425c76&&_0x425c76[_0x3f81e8('0x3')]===0x0?db['UserProfileResource'][_0x3f81e8('0x53')]({'name':_0x106c25[_0x3f81e8('0x26')],'resourceId':_0x106c25['id'],'type':_0x425c76[_0x3f81e8('0x26')],'sectionId':_0x425c76['id']},{})[_0x3f81e8('0x3d')](function(){return _0x2bd0dd;}):_0x2bd0dd;})[_0x1eaae8('0x1e')](function(_0x54b64b){const _0x724061=_0x1eaae8;logger[_0x724061('0x6')](_0x724061('0x28'),_0x54b64b);throw _0x54b64b;});}return _0x2bd0dd;})[_0x453ad0('0x3d')](respondWithResult(_0x53f860,0xc9))[_0x453ad0('0x1e')](handleError(_0x53f860,null));},exports[_0xf84920('0x19')]=function(_0x4a5957,_0x509630){const _0x3f2cc6=_0xf84920;let _0x1d8c42;return db[_0x3f2cc6('0x13')]['findOne']({'where':{'id':_0x4a5957[_0x3f2cc6('0x1d')]['id']}})['then'](handleEntityNotFound(_0x509630,null))[_0x3f2cc6('0x3d')](saveUpdates(_0x4a5957[_0x3f2cc6('0x31')],null))[_0x3f2cc6('0x3d')](function(_0x1184df){const _0x2a6b13=_0x3f2cc6;if(_0x1184df)return _0x1d8c42=_0x1184df,db[_0x2a6b13('0x13')][_0x2a6b13('0x11')]({'raw':!![]});})[_0x3f2cc6('0x3d')](function(_0x212498){const _0x4138a2=_0x3f2cc6;if(_0x212498){const _0x16ec7d=fs[_0x4138a2('0x1c')](path[_0x4138a2('0x22')](config[_0x4138a2('0x21')],_0x4138a2('0x32')),_0x4138a2('0x2d')),_0x163224=fs[_0x4138a2('0x1c')](path['join'](config[_0x4138a2('0x21')],_0x4138a2('0x48')),'utf8'),_0x5e25cc=ejs[_0x4138a2('0x2e')](_0x16ec7d,{'trunks':_0x212498||[]});fs[_0x4138a2('0x44')](_0x4138a2('0x52'),_0x5e25cc);const _0x3d4bd1=ejs['render'](_0x163224,{'trunks':_0x212498||[]});return fs[_0x4138a2('0x44')](_0x4138a2('0x45'),_0x3d4bd1),respondWithRpcPromise(_0x4138a2('0x3f'),_0x4138a2('0x19'),{'module':_0x4138a2('0xa')});}return null;})[_0x3f2cc6('0x3d')](function(_0x250386){if(_0x250386)return _0x1d8c42;})[_0x3f2cc6('0x3d')](respondWithResult(_0x509630,null))[_0x3f2cc6('0x1e')](handleError(_0x509630,null));},exports[_0xf84920('0x4f')]=function(_0x4a50fb,_0x5d5023){const _0x17b540=_0xf84920;return db[_0x17b540('0x13')][_0x17b540('0x42')]({'where':{'id':_0x4a50fb[_0x17b540('0x1d')]['id']}})['then'](handleEntityNotFound(_0x5d5023,null))[_0x17b540('0x3d')](removeEntity(_0x5d5023,null))[_0x17b540('0x3d')](function(){const _0x100a6f=_0x17b540;return db[_0x100a6f('0x13')][_0x100a6f('0x11')]({'raw':!![]});})[_0x17b540('0x3d')](function(_0x315a33){const _0x609c81=_0x17b540,_0x1adc29=fs[_0x609c81('0x1c')](path[_0x609c81('0x22')](config[_0x609c81('0x21')],_0x609c81('0x32')),_0x609c81('0x2d')),_0x4fe824=fs[_0x609c81('0x1c')](path[_0x609c81('0x22')](config[_0x609c81('0x21')],_0x609c81('0x48')),_0x609c81('0x2d')),_0x2757f4=ejs[_0x609c81('0x2e')](_0x1adc29,{'trunks':_0x315a33}),_0x578af0=ejs[_0x609c81('0x2e')](_0x4fe824,{'trunks':_0x315a33});return fs[_0x609c81('0x44')]('/etc/asterisk/sip_xcally_trunks.conf',_0x2757f4),fs[_0x609c81('0x44')](_0x609c81('0x45'),_0x578af0),respondWithRpcPromise(_0x609c81('0x3f'),_0x609c81('0x4f'),{'module':'chan_sip.so'});})['catch'](handleError(_0x5d5023,null));};
\ No newline at end of file
+const a643_0x4549=['error','createdAt','destroy','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','Reload','role','sort','json','options','writeFileSync','clone','join','Trunks','body','autoAssociation','params','/etc/asterisk/sip_xcally_trunks.conf','root','nolimit','get','client','render','where','../../config/environment','debug','order','rawAttributes','registry','lodash','merge','UserProfileSection','UserProfileResource','create','intersection','like','offset','updatedAt','then','key','readFileSync','request\x20sent','stringify','update','info','pick','keys','name','userProfileId','include','stack','/etc/asterisk/sip_xcally_registers.conf','includeAll','fieldName','path','count','utf8','query','Trunk,\x20%s,\x20%s,\x20%s','catch','chan_sip.so','status','fields','jayson/promise','undefined','map','filters','attributes','files/templates/registry.ejs','limit','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','sequelize','Trunk,\x20%s,\x20%s','filter','model','Content-Range','files/templates/trunk.ejs','set','show','type','ejs','message','sendStatus','http','../../components/parsers/qs','../../config/logger','findOne','omit','Trunk','findAll'];(function(_0x48b081,_0x4549fc){const _0x5ea2ab=function(_0x491fd3){while(--_0x491fd3){_0x48b081['push'](_0x48b081['shift']());}};_0x5ea2ab(++_0x4549fc);}(a643_0x4549,0x163));const a643_0x5ea2=function(_0x48b081,_0x4549fc){_0x48b081=_0x48b081-0x0;let _0x5ea2ab=a643_0x4549[_0x48b081];return _0x5ea2ab;};const _0x59ed21=a643_0x5ea2;'use strict';const path=require(_0x59ed21('0x3b')),ejs=require(_0x59ed21('0x55')),fs=require('fs'),_=require(_0x59ed21('0x22')),qs=require(_0x59ed21('0x59')),logger=require(_0x59ed21('0x0'))('api'),config=require(_0x59ed21('0x1d')),db=require('../../mysqldb')['db'],{Op}=require(_0x59ed21('0x4c')),jayson=require(_0x59ed21('0x44')),client=jayson[_0x59ed21('0x1a')][_0x59ed21('0x58')]({'port':0x232a});function respondWithRpcPromise(_0x491fd3,_0xbaed19,_0x93e4bc,_0x4307d4){return new Promise(function(_0x231e57,_0xe3d0eb){const _0x259eec=a643_0x5ea2,_0x15dccc=_0x4307d4||client;return _0x15dccc['request'](_0x491fd3,_0x93e4bc)[_0x259eec('0x2b')](function(_0x54e172){const _0x2904ac=_0x259eec;logger[_0x2904ac('0x31')](_0x2904ac('0x4d'),_0xbaed19,_0x2904ac('0x2e')),logger[_0x2904ac('0x1e')](_0x2904ac('0x3f'),_0xbaed19,_0x2904ac('0x2e'),JSON[_0x2904ac('0x2f')](_0x54e172));if(_0x54e172[_0x2904ac('0x5')]){if(_0x54e172[_0x2904ac('0x5')]['code']===0x1f4)return logger[_0x2904ac('0x5')](_0x2904ac('0x4d'),_0xbaed19,_0x54e172[_0x2904ac('0x5')][_0x2904ac('0x56')]),_0xe3d0eb(_0x54e172[_0x2904ac('0x5')][_0x2904ac('0x56')]);return logger['error'](_0x2904ac('0x4d'),_0xbaed19,_0x54e172[_0x2904ac('0x5')]['message']),_0x231e57(_0x54e172[_0x2904ac('0x5')][_0x2904ac('0x56')]);}else logger['info'](_0x2904ac('0x4d'),_0xbaed19,_0x2904ac('0x2e')),_0x231e57(_0x54e172['result'][_0x2904ac('0x56')]);})['catch'](function(_0x20c63d){const _0x11a3d4=_0x259eec;logger[_0x11a3d4('0x5')](_0x11a3d4('0x4d'),_0xbaed19,_0x20c63d),_0xe3d0eb(_0x20c63d);});});}function respondWithResult(_0x2cafe8,_0x18afdb){return _0x18afdb=_0x18afdb||0xc8,function(_0x5bd297){const _0x8b7873=a643_0x5ea2;if(_0x5bd297)return _0x2cafe8[_0x8b7873('0x42')](_0x18afdb)[_0x8b7873('0xd')](_0x5bd297);};}function respondWithFilteredResult(_0x35d7a2,_0x3a80f0){return function(_0x45e225){const _0x432474=a643_0x5ea2;if(_0x45e225){const _0x2e3317=_0x45e225[_0x432474('0x3c')],_0x43fd6c=_0x3a80f0[_0x432474('0x29')];let _0x1b1564=_0x3a80f0[_0x432474('0x29')]+_0x3a80f0[_0x432474('0x4a')],_0x2503f7;return _0x1b1564>=_0x2e3317?(_0x1b1564=_0x2e3317,_0x2503f7=0xc8):_0x2503f7=0xce,_0x35d7a2[_0x432474('0x42')](_0x2503f7),_0x35d7a2[_0x432474('0x52')](_0x432474('0x50'),_0x43fd6c+'-'+_0x1b1564+'/'+_0x2e3317)['json'](_0x45e225);}return null;};}function saveUpdates(_0x25525c){return function(_0x3664f4){const _0x33fe99=a643_0x5ea2;if(_0x3664f4)return _0x3664f4[_0x33fe99('0x30')](_0x25525c)[_0x33fe99('0x2b')](function(_0x47fc68){return _0x47fc68;});return null;};}function removeEntity(_0x399cc4){return function(_0x4234c4){const _0xe875b5=a643_0x5ea2;if(_0x4234c4)return _0x4234c4[_0xe875b5('0x7')]()[_0xe875b5('0x2b')](function(){const _0x57c5a4=_0xe875b5,_0x211eea=_0x4234c4['get']({'plain':!![]}),_0xee8508=_0x57c5a4('0x12');return db[_0x57c5a4('0x25')][_0x57c5a4('0x7')]({'where':{'type':_0xee8508,'resourceId':_0x211eea['id']}})[_0x57c5a4('0x2b')](function(){return _0x4234c4;});})[_0xe875b5('0x2b')](function(){const _0x53ab58=_0xe875b5;_0x399cc4[_0x53ab58('0x42')](0xcc)['end']();});};}function handleEntityNotFound(_0x9957fb){return function(_0x2423ef){const _0x3c3787=a643_0x5ea2;return!_0x2423ef&&_0x9957fb[_0x3c3787('0x57')](0x194),_0x2423ef;};}function handleError(_0x2e805b,_0x142239){return _0x142239=_0x142239||0x1f4,function(_0x2e3d58){const _0xfdeee4=a643_0x5ea2;logger['error'](_0x2e3d58[_0xfdeee4('0x37')]),_0x2e3d58[_0xfdeee4('0x34')]&&delete _0x2e3d58[_0xfdeee4('0x34')],_0x2e805b['status'](_0x142239)['send'](_0x2e3d58);};}exports['index']=function(_0x1938ea,_0x1ad694){const _0x4b4ce7=_0x59ed21;let _0x22d0e1={};const _0x3207c7={},_0x320705={'count':0x0,'rows':[]},_0x4e4d19=_[_0x4b4ce7('0x46')](db['Trunk']['rawAttributes'],function(_0x41edf1){const _0x18a0a7=_0x4b4ce7;return{'name':_0x41edf1[_0x18a0a7('0x3a')],'type':_0x41edf1[_0x18a0a7('0x54')][_0x18a0a7('0x2c')]};});_0x3207c7[_0x4b4ce7('0x4f')]=_[_0x4b4ce7('0x46')](_0x4e4d19,'name'),_0x3207c7[_0x4b4ce7('0x3e')]=_[_0x4b4ce7('0x33')](_0x1938ea[_0x4b4ce7('0x3e')]),_0x3207c7['filters']=_[_0x4b4ce7('0x27')](_0x3207c7[_0x4b4ce7('0x4f')],_0x3207c7[_0x4b4ce7('0x3e')]),_0x22d0e1[_0x4b4ce7('0x48')]=_[_0x4b4ce7('0x27')](_0x3207c7[_0x4b4ce7('0x4f')],qs[_0x4b4ce7('0x43')](_0x1938ea[_0x4b4ce7('0x3e')][_0x4b4ce7('0x43')])),_0x22d0e1[_0x4b4ce7('0x48')]=_0x22d0e1['attributes']['length']?_0x22d0e1['attributes']:_0x3207c7[_0x4b4ce7('0x4f')];typeof _0x1938ea['query'][_0x4b4ce7('0x18')]===_0x4b4ce7('0x45')&&(_0x22d0e1[_0x4b4ce7('0x4a')]=qs[_0x4b4ce7('0x4a')](_0x1938ea['query'][_0x4b4ce7('0x4a')]),_0x22d0e1[_0x4b4ce7('0x29')]=qs[_0x4b4ce7('0x29')](_0x1938ea[_0x4b4ce7('0x3e')][_0x4b4ce7('0x29')]));_0x22d0e1[_0x4b4ce7('0x1f')]=qs[_0x4b4ce7('0xc')](_0x1938ea[_0x4b4ce7('0x3e')][_0x4b4ce7('0xc')]),_0x22d0e1[_0x4b4ce7('0x1c')]=qs[_0x4b4ce7('0x47')](_[_0x4b4ce7('0x32')](_0x1938ea[_0x4b4ce7('0x3e')],_0x3207c7[_0x4b4ce7('0x47')]),_0x4e4d19);_0x1938ea[_0x4b4ce7('0x3e')][_0x4b4ce7('0x4e')]&&(_0x22d0e1[_0x4b4ce7('0x1c')]=_['merge'](_0x22d0e1[_0x4b4ce7('0x1c')],{[Op['or']]:_['map'](_0x4e4d19,function(_0x90e657){const _0x418a4a=_0x4b4ce7;if(_0x90e657['type']!=='VIRTUAL'){const _0x4ec648={};return _0x4ec648[_0x90e657[_0x418a4a('0x34')]]={[Op[_0x418a4a('0x28')]]:'%'+_0x1938ea[_0x418a4a('0x3e')][_0x418a4a('0x4e')]+'%'},_0x4ec648;}})}));_0x22d0e1=_[_0x4b4ce7('0x23')]({},_0x22d0e1,_0x1938ea[_0x4b4ce7('0xe')]);const _0x51147f={'where':_0x22d0e1['where']};return db['Trunk'][_0x4b4ce7('0x3c')](_0x51147f)[_0x4b4ce7('0x2b')](function(_0x5d3583){const _0xa702f9=_0x4b4ce7;return _0x320705['count']=_0x5d3583,_0x1938ea['query'][_0xa702f9('0x39')]&&(_0x22d0e1[_0xa702f9('0x36')]=[{'all':!![]}]),db[_0xa702f9('0x3')]['findAll'](_0x22d0e1);})[_0x4b4ce7('0x2b')](function(_0x3326ed){return _0x320705['rows']=_0x3326ed,_0x320705;})[_0x4b4ce7('0x2b')](respondWithFilteredResult(_0x1ad694,_0x22d0e1))['catch'](handleError(_0x1ad694,null));},exports[_0x59ed21('0x53')]=function(_0x1dd4c2,_0x38c81b){const _0x4a6c5b=_0x59ed21;let _0x50612b={'raw':![],'where':{'id':_0x1dd4c2[_0x4a6c5b('0x15')]['id']}};const _0x34cb22={};return _0x34cb22[_0x4a6c5b('0x4f')]=_['keys'](db[_0x4a6c5b('0x3')][_0x4a6c5b('0x20')]),_0x34cb22[_0x4a6c5b('0x3e')]=_[_0x4a6c5b('0x33')](_0x1dd4c2[_0x4a6c5b('0x3e')]),_0x34cb22[_0x4a6c5b('0x47')]=_['intersection'](_0x34cb22[_0x4a6c5b('0x4f')],_0x34cb22[_0x4a6c5b('0x3e')]),_0x50612b[_0x4a6c5b('0x48')]=_[_0x4a6c5b('0x27')](_0x34cb22[_0x4a6c5b('0x4f')],qs[_0x4a6c5b('0x43')](_0x1dd4c2[_0x4a6c5b('0x3e')][_0x4a6c5b('0x43')])),_0x50612b[_0x4a6c5b('0x48')]=_0x50612b['attributes']['length']?_0x50612b[_0x4a6c5b('0x48')]:_0x34cb22['model'],_0x1dd4c2['query'][_0x4a6c5b('0x39')]&&(_0x50612b['include']=[{'all':!![]}]),_0x50612b=_['merge']({},_0x50612b,_0x1dd4c2['options']),db[_0x4a6c5b('0x3')][_0x4a6c5b('0x1')](_0x50612b)[_0x4a6c5b('0x2b')](handleEntityNotFound(_0x38c81b,null))[_0x4a6c5b('0x2b')](respondWithResult(_0x38c81b,null))['catch'](handleError(_0x38c81b,null));},exports[_0x59ed21('0x10')]=function(_0x1c7fbb,_0x50c945){const _0x278b33=_0x59ed21;let _0x1f1111={'where':{'id':_0x1c7fbb[_0x278b33('0x15')]['id']}};const _0x348541={};return _0x348541[_0x278b33('0x4f')]=_['keys'](db['Trunk'][_0x278b33('0x20')]),_0x1f1111[_0x278b33('0x48')]=_['intersection'](_0x348541[_0x278b33('0x4f')],qs[_0x278b33('0x43')](_0x1c7fbb[_0x278b33('0x3e')][_0x278b33('0x43')])),_0x1f1111[_0x278b33('0x48')]=_0x1f1111[_0x278b33('0x48')]['length']?_0x1f1111[_0x278b33('0x48')]:_0x348541[_0x278b33('0x4f')],_0x1c7fbb['query'][_0x278b33('0x39')]&&(_0x1f1111[_0x278b33('0x36')]=[{'all':!![]}]),_0x1f1111=_['merge']({},_0x1f1111,_0x1c7fbb[_0x278b33('0xe')]),db[_0x278b33('0x3')][_0x278b33('0x1')](_0x1f1111)[_0x278b33('0x2b')](handleEntityNotFound(_0x50c945,null))[_0x278b33('0x2b')](function(_0x3d04ea){const _0x53817e=_0x278b33;if(_0x3d04ea){let _0x526865=_0x3d04ea[_0x53817e('0x19')]({'plain':!![]});return _0x526865=qs[_0x53817e('0x2')](_0x526865,['id',_0x53817e('0x6'),_0x53817e('0x2a')]),_0x1c7fbb[_0x53817e('0x13')]=_['omit'](_0x1c7fbb[_0x53817e('0x13')],['id',_0x53817e('0x6'),'updatedAt']),db[_0x53817e('0x3')]['create'](_[_0x53817e('0x23')](_0x526865,_0x1c7fbb[_0x53817e('0x13')]),{'include':_0x1c7fbb['query'][_0x53817e('0x39')]?[{'all':!![]}]:undefined})[_0x53817e('0x2b')](function(_0x1d8bf5){const _0x53dbd6=_0x53817e,_0x3ffc7c=_0x1c7fbb[_0x53dbd6('0x8')][_0x53dbd6('0x19')]({'plain':!![]});if(!_0x3ffc7c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3ffc7c[_0x53dbd6('0xb')]==='user'){const _0x1e0926=_0x1d8bf5[_0x53dbd6('0x19')]({'plain':!![]}),_0x37d0c9=_0x53dbd6('0x12');return db['UserProfileSection'][_0x53dbd6('0x1')]({'where':{'name':_0x37d0c9,'userProfileId':_0x3ffc7c['userProfileId']},'raw':!![]})[_0x53dbd6('0x2b')](function(_0x1f76ef){const _0x982f52=_0x53dbd6;return _0x1f76ef&&_0x1f76ef[_0x982f52('0x14')]===0x0?db[_0x982f52('0x25')]['create']({'name':_0x1e0926[_0x982f52('0x34')],'resourceId':_0x1e0926['id'],'type':_0x1f76ef[_0x982f52('0x34')],'sectionId':_0x1f76ef['id']},{})[_0x982f52('0x2b')](function(){return _0x1d8bf5;}):_0x1d8bf5;})[_0x53dbd6('0x40')](function(_0x408bbe){const _0x4fa3df=_0x53dbd6;logger['error'](_0x4fa3df('0x4b'),_0x408bbe);throw _0x408bbe;});}return _0x1d8bf5;});}})[_0x278b33('0x2b')](respondWithResult(_0x50c945,0xc9))[_0x278b33('0x40')](handleError(_0x50c945,null));},exports['create']=function(_0x4448c1,_0x33eaed){const _0x143cfe=_0x59ed21;let _0x175264;return db['Trunk'][_0x143cfe('0x26')](_0x4448c1[_0x143cfe('0x13')],{'raw':!![]})['then'](function(_0x1284b0){const _0x5c1874=_0x143cfe;return _0x175264=_0x1284b0,db['Trunk'][_0x5c1874('0x4')]({'raw':!![]});})[_0x143cfe('0x2b')](function(_0x40cfb3){const _0x5dcb1e=_0x143cfe,_0x48bca9=fs[_0x5dcb1e('0x2d')](path[_0x5dcb1e('0x11')](config[_0x5dcb1e('0x17')],'files/templates/trunk.ejs'),_0x5dcb1e('0x3d')),_0x1ba1b6=fs['readFileSync'](path[_0x5dcb1e('0x11')](config[_0x5dcb1e('0x17')],_0x5dcb1e('0x49')),_0x5dcb1e('0x3d')),_0x35031f=ejs[_0x5dcb1e('0x1b')](_0x48bca9,{'trunks':_0x40cfb3||[]});fs[_0x5dcb1e('0xf')]('/etc/asterisk/sip_xcally_trunks.conf',_0x35031f);if(_0x175264[_0x5dcb1e('0x21')]){const _0x4c4b3b=ejs['render'](_0x1ba1b6,{'trunks':_0x40cfb3||[]});fs[_0x5dcb1e('0xf')](_0x5dcb1e('0x38'),_0x4c4b3b);}})[_0x143cfe('0x2b')](function(){const _0x46e5f2=_0x143cfe;return respondWithRpcPromise(_0x46e5f2('0xa'),_0x46e5f2('0x26'),{'module':_0x46e5f2('0x41')});})[_0x143cfe('0x2b')](function(){const _0x2692af=_0x143cfe,_0x3e7a0e=_0x4448c1['user'][_0x2692af('0x19')]({'plain':!![]});if(!_0x3e7a0e)throw new Error(_0x2692af('0x9'));if(_0x3e7a0e[_0x2692af('0xb')]===_0x2692af('0x8')){const _0xaf8347=_0x175264['get']({'plain':!![]});return db[_0x2692af('0x24')]['findOne']({'where':{'name':'Trunks','userProfileId':_0x3e7a0e[_0x2692af('0x35')]},'raw':!![]})[_0x2692af('0x2b')](function(_0x233761){const _0x34e79f=_0x2692af;return _0x233761&&_0x233761[_0x34e79f('0x14')]===0x0?db[_0x34e79f('0x25')]['create']({'name':_0xaf8347[_0x34e79f('0x34')],'resourceId':_0xaf8347['id'],'type':_0x233761[_0x34e79f('0x34')],'sectionId':_0x233761['id']},{})[_0x34e79f('0x2b')](function(){return _0x175264;}):_0x175264;})['catch'](function(_0x32d865){const _0x20c5ac=_0x2692af;logger[_0x20c5ac('0x5')](_0x20c5ac('0x4b'),_0x32d865);throw _0x32d865;});}return _0x175264;})[_0x143cfe('0x2b')](respondWithResult(_0x33eaed,0xc9))[_0x143cfe('0x40')](handleError(_0x33eaed,null));},exports[_0x59ed21('0x30')]=function(_0x5a9439,_0x1e3e60){const _0x2f730d=_0x59ed21;let _0x4e25aa;return db[_0x2f730d('0x3')][_0x2f730d('0x1')]({'where':{'id':_0x5a9439[_0x2f730d('0x15')]['id']}})[_0x2f730d('0x2b')](handleEntityNotFound(_0x1e3e60,null))[_0x2f730d('0x2b')](saveUpdates(_0x5a9439[_0x2f730d('0x13')],null))['then'](function(_0x374e8e){if(_0x374e8e)return _0x4e25aa=_0x374e8e,db['Trunk']['findAll']({'raw':!![]});})['then'](function(_0x5e68dd){const _0x63026=_0x2f730d;if(_0x5e68dd){const _0x41ebaf=fs[_0x63026('0x2d')](path['join'](config[_0x63026('0x17')],_0x63026('0x51')),_0x63026('0x3d')),_0x251a50=fs[_0x63026('0x2d')](path['join'](config[_0x63026('0x17')],_0x63026('0x49')),_0x63026('0x3d')),_0x2e63ec=ejs[_0x63026('0x1b')](_0x41ebaf,{'trunks':_0x5e68dd||[]});fs[_0x63026('0xf')]('/etc/asterisk/sip_xcally_trunks.conf',_0x2e63ec);const _0x134da8=ejs[_0x63026('0x1b')](_0x251a50,{'trunks':_0x5e68dd||[]});return fs[_0x63026('0xf')](_0x63026('0x38'),_0x134da8),respondWithRpcPromise(_0x63026('0xa'),_0x63026('0x30'),{'module':_0x63026('0x41')});}return null;})[_0x2f730d('0x2b')](function(_0x46d516){if(_0x46d516)return _0x4e25aa;})[_0x2f730d('0x2b')](respondWithResult(_0x1e3e60,null))['catch'](handleError(_0x1e3e60,null));},exports[_0x59ed21('0x7')]=function(_0x388a64,_0x463b){const _0x2c8f09=_0x59ed21;return db[_0x2c8f09('0x3')]['findOne']({'where':{'id':_0x388a64['params']['id']}})[_0x2c8f09('0x2b')](handleEntityNotFound(_0x463b,null))[_0x2c8f09('0x2b')](removeEntity(_0x463b,null))[_0x2c8f09('0x2b')](function(){const _0x2ce4a8=_0x2c8f09;return db[_0x2ce4a8('0x3')][_0x2ce4a8('0x4')]({'raw':!![]});})[_0x2c8f09('0x2b')](function(_0x364110){const _0x1d2393=_0x2c8f09,_0x3819c4=fs[_0x1d2393('0x2d')](path[_0x1d2393('0x11')](config[_0x1d2393('0x17')],_0x1d2393('0x51')),'utf8'),_0x5b5397=fs[_0x1d2393('0x2d')](path[_0x1d2393('0x11')](config[_0x1d2393('0x17')],_0x1d2393('0x49')),_0x1d2393('0x3d')),_0x290e57=ejs[_0x1d2393('0x1b')](_0x3819c4,{'trunks':_0x364110}),_0xb7ab7a=ejs['render'](_0x5b5397,{'trunks':_0x364110});return fs[_0x1d2393('0xf')](_0x1d2393('0x16'),_0x290e57),fs['writeFileSync'](_0x1d2393('0x38'),_0xb7ab7a),respondWithRpcPromise(_0x1d2393('0xa'),_0x1d2393('0x7'),{'module':_0x1d2393('0x41')});})['catch'](handleError(_0x463b,null));};
\ No newline at end of file