Built motion from commit 5fcd269f5146f10cf3129722d518881dfac64576. Version 3.0.0...
[motion-next.git] / server / api / trunk / trunk.controller.js
1 const a643_0xb981=['intersection','body','message','model','filters','then','files/templates/registry.ejs','files/templates/trunk.ejs','path','create','fieldName','writeFileSync','pick','where','info','include','autoAssociation','VIRTUAL','role','status','stringify','request','utf8','../../mysqldb','jayson/promise','ejs','catch','destroy','render','params','userProfileId','length','../../config/environment','../../config/logger','registry','type','filter','query','nolimit','UserProfileResource','Reload','index','sendStatus','send','update','createdAt','rows','user','UserProfileSection','chan_sip.so','updatedAt','rawAttributes','options','order','readFileSync','end','includeAll','root','Trunk,\x20%s,\x20%s,\x20%s','attributes','omit','lodash','fields','http','Unable\x20to\x20retrieve\x20the\x20current\x20user','stack','key','join','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','keys','findAll','limit','undefined','map','json','offset','name','Trunk,\x20%s,\x20%s','findOne','sort','sequelize','get','/etc/asterisk/sip_xcally_trunks.conf','api','../../components/parsers/qs','clone','merge','count','error','Trunks','request\x20sent','Trunk','/etc/asterisk/sip_xcally_registers.conf'];(function(_0x5e74de,_0xb98168){const _0x389dee=function(_0x7d3d5b){while(--_0x7d3d5b){_0x5e74de['push'](_0x5e74de['shift']());}};_0x389dee(++_0xb98168);}(a643_0xb981,0x177));const a643_0x389d=function(_0x5e74de,_0xb98168){_0x5e74de=_0x5e74de-0x0;let _0x389dee=a643_0xb981[_0x5e74de];return _0x389dee;};const _0x2529f4=a643_0x389d;'use strict';const path=require(_0x2529f4('0x5')),ejs=require(_0x2529f4('0x16')),fs=require('fs'),_=require(_0x2529f4('0x3a')),qs=require(_0x2529f4('0x51')),logger=require(_0x2529f4('0x1e'))(_0x2529f4('0x50')),config=require(_0x2529f4('0x1d')),db=require(_0x2529f4('0x14'))['db'],{Op}=require(_0x2529f4('0x4d')),jayson=require(_0x2529f4('0x15')),client=jayson['client'][_0x2529f4('0x3c')]({'port':0x232a});function respondWithRpcPromise(_0x7d3d5b,_0x422bdf,_0x5974f4,_0x28289c){return new Promise(function(_0x57fb1a,_0x2450b7){const _0x39702f=a643_0x389d,_0x27a2ee=_0x28289c||client;return _0x27a2ee[_0x39702f('0x12')](_0x7d3d5b,_0x5974f4)[_0x39702f('0x2')](function(_0x3028bc){const _0x3e86ff=_0x39702f;logger[_0x3e86ff('0xb')](_0x3e86ff('0x4a'),_0x422bdf,_0x3e86ff('0x57')),logger['debug'](_0x3e86ff('0x37'),_0x422bdf,'request\x20sent',JSON[_0x3e86ff('0x11')](_0x3028bc));if(_0x3028bc[_0x3e86ff('0x55')]){if(_0x3028bc[_0x3e86ff('0x55')]['code']===0x1f4)return logger[_0x3e86ff('0x55')](_0x3e86ff('0x4a'),_0x422bdf,_0x3028bc[_0x3e86ff('0x55')]['message']),_0x2450b7(_0x3028bc['error'][_0x3e86ff('0x5c')]);return logger[_0x3e86ff('0x55')](_0x3e86ff('0x4a'),_0x422bdf,_0x3028bc['error'][_0x3e86ff('0x5c')]),_0x57fb1a(_0x3028bc[_0x3e86ff('0x55')][_0x3e86ff('0x5c')]);}else logger[_0x3e86ff('0xb')](_0x3e86ff('0x4a'),_0x422bdf,_0x3e86ff('0x57')),_0x57fb1a(_0x3028bc['result']['message']);})[_0x39702f('0x17')](function(_0xb66fe4){const _0x86bdbd=_0x39702f;logger[_0x86bdbd('0x55')](_0x86bdbd('0x4a'),_0x422bdf,_0xb66fe4),_0x2450b7(_0xb66fe4);});});}function respondWithResult(_0x20c6e2,_0x52ee5c){return _0x52ee5c=_0x52ee5c||0xc8,function(_0x53918b){const _0x4778a8=a643_0x389d;if(_0x53918b)return _0x20c6e2[_0x4778a8('0x10')](_0x52ee5c)[_0x4778a8('0x47')](_0x53918b);};}function respondWithFilteredResult(_0x5292e2,_0x1f1111){return function(_0x2459eb){const _0x34975d=a643_0x389d;if(_0x2459eb){const _0x107c8a=_0x2459eb['count'],_0x4d9dcd=_0x1f1111[_0x34975d('0x48')];let _0x2bf923=_0x1f1111[_0x34975d('0x48')]+_0x1f1111['limit'],_0x275bf2;return _0x2bf923>=_0x107c8a?(_0x2bf923=_0x107c8a,_0x275bf2=0xc8):_0x275bf2=0xce,_0x5292e2[_0x34975d('0x10')](_0x275bf2),_0x5292e2['set']('Content-Range',_0x4d9dcd+'-'+_0x2bf923+'/'+_0x107c8a)[_0x34975d('0x47')](_0x2459eb);}return null;};}function saveUpdates(_0x1879d7){return function(_0x39136c){const _0x5bfa00=a643_0x389d;if(_0x39136c)return _0x39136c[_0x5bfa00('0x29')](_0x1879d7)[_0x5bfa00('0x2')](function(_0x188362){return _0x188362;});return null;};}function removeEntity(_0x250a1b){return function(_0x19572f){const _0x1245b7=a643_0x389d;if(_0x19572f)return _0x19572f['destroy']()[_0x1245b7('0x2')](function(){const _0x7f2398=_0x1245b7,_0x4c242f=_0x19572f[_0x7f2398('0x4e')]({'plain':!![]}),_0xd5967a=_0x7f2398('0x56');return db[_0x7f2398('0x24')][_0x7f2398('0x18')]({'where':{'type':_0xd5967a,'resourceId':_0x4c242f['id']}})['then'](function(){return _0x19572f;});})[_0x1245b7('0x2')](function(){const _0x40b8fa=_0x1245b7;_0x250a1b['status'](0xcc)[_0x40b8fa('0x34')]();});};}function handleEntityNotFound(_0x179f12){return function(_0x53008b){const _0x10aa0e=a643_0x389d;return!_0x53008b&&_0x179f12[_0x10aa0e('0x27')](0x194),_0x53008b;};}function handleError(_0x4352aa,_0x3d5e72){return _0x3d5e72=_0x3d5e72||0x1f4,function(_0x7f8ee8){const _0x555cbd=a643_0x389d;logger['error'](_0x7f8ee8[_0x555cbd('0x3e')]),_0x7f8ee8['name']&&delete _0x7f8ee8['name'],_0x4352aa['status'](_0x3d5e72)[_0x555cbd('0x28')](_0x7f8ee8);};}exports[_0x2529f4('0x26')]=function(_0x12fdff,_0x42306c){const _0x508d17=_0x2529f4;let _0xf9265e={};const _0x3816a4={},_0x40c045={'count':0x0,'rows':[]},_0x965b8a=_[_0x508d17('0x46')](db[_0x508d17('0x58')][_0x508d17('0x30')],function(_0x432555){const _0x57c53c=_0x508d17;return{'name':_0x432555[_0x57c53c('0x7')],'type':_0x432555[_0x57c53c('0x20')][_0x57c53c('0x3f')]};});_0x3816a4[_0x508d17('0x0')]=_[_0x508d17('0x46')](_0x965b8a,_0x508d17('0x49')),_0x3816a4[_0x508d17('0x22')]=_[_0x508d17('0x42')](_0x12fdff['query']),_0x3816a4[_0x508d17('0x1')]=_[_0x508d17('0x5a')](_0x3816a4['model'],_0x3816a4[_0x508d17('0x22')]),_0xf9265e[_0x508d17('0x38')]=_[_0x508d17('0x5a')](_0x3816a4[_0x508d17('0x0')],qs['fields'](_0x12fdff['query'][_0x508d17('0x3b')])),_0xf9265e['attributes']=_0xf9265e['attributes']['length']?_0xf9265e[_0x508d17('0x38')]:_0x3816a4[_0x508d17('0x0')];typeof _0x12fdff[_0x508d17('0x22')][_0x508d17('0x23')]===_0x508d17('0x45')&&(_0xf9265e[_0x508d17('0x44')]=qs[_0x508d17('0x44')](_0x12fdff[_0x508d17('0x22')][_0x508d17('0x44')]),_0xf9265e[_0x508d17('0x48')]=qs[_0x508d17('0x48')](_0x12fdff[_0x508d17('0x22')][_0x508d17('0x48')]));_0xf9265e[_0x508d17('0x32')]=qs[_0x508d17('0x4c')](_0x12fdff[_0x508d17('0x22')][_0x508d17('0x4c')]),_0xf9265e['where']=qs[_0x508d17('0x1')](_[_0x508d17('0x9')](_0x12fdff['query'],_0x3816a4[_0x508d17('0x1')]),_0x965b8a);_0x12fdff[_0x508d17('0x22')][_0x508d17('0x21')]&&(_0xf9265e['where']=_[_0x508d17('0x53')](_0xf9265e[_0x508d17('0xa')],{[Op['or']]:_[_0x508d17('0x46')](_0x965b8a,function(_0x9a8ccd){const _0x2ab42b=_0x508d17;if(_0x9a8ccd[_0x2ab42b('0x20')]!==_0x2ab42b('0xe')){const _0x31f9f8={};return _0x31f9f8[_0x9a8ccd[_0x2ab42b('0x49')]]={[Op['like']]:'%'+_0x12fdff['query'][_0x2ab42b('0x21')]+'%'},_0x31f9f8;}})}));_0xf9265e=_['merge']({},_0xf9265e,_0x12fdff[_0x508d17('0x31')]);const _0x245bbe={'where':_0xf9265e['where']};return db[_0x508d17('0x58')][_0x508d17('0x54')](_0x245bbe)['then'](function(_0x56745f){const _0x27dc78=_0x508d17;return _0x40c045[_0x27dc78('0x54')]=_0x56745f,_0x12fdff[_0x27dc78('0x22')][_0x27dc78('0x35')]&&(_0xf9265e[_0x27dc78('0xc')]=[{'all':!![]}]),db[_0x27dc78('0x58')][_0x27dc78('0x43')](_0xf9265e);})[_0x508d17('0x2')](function(_0x396ce9){const _0xbfb18b=_0x508d17;return _0x40c045[_0xbfb18b('0x2b')]=_0x396ce9,_0x40c045;})[_0x508d17('0x2')](respondWithFilteredResult(_0x42306c,_0xf9265e))[_0x508d17('0x17')](handleError(_0x42306c,null));},exports['show']=function(_0x5f02e9,_0x4cfc21){const _0xf131b5=_0x2529f4;let _0x473323={'raw':![],'where':{'id':_0x5f02e9[_0xf131b5('0x1a')]['id']}};const _0x3c920d={};return _0x3c920d[_0xf131b5('0x0')]=_[_0xf131b5('0x42')](db[_0xf131b5('0x58')]['rawAttributes']),_0x3c920d[_0xf131b5('0x22')]=_[_0xf131b5('0x42')](_0x5f02e9['query']),_0x3c920d[_0xf131b5('0x1')]=_[_0xf131b5('0x5a')](_0x3c920d[_0xf131b5('0x0')],_0x3c920d[_0xf131b5('0x22')]),_0x473323[_0xf131b5('0x38')]=_[_0xf131b5('0x5a')](_0x3c920d[_0xf131b5('0x0')],qs[_0xf131b5('0x3b')](_0x5f02e9[_0xf131b5('0x22')]['fields'])),_0x473323[_0xf131b5('0x38')]=_0x473323[_0xf131b5('0x38')]['length']?_0x473323[_0xf131b5('0x38')]:_0x3c920d[_0xf131b5('0x0')],_0x5f02e9['query'][_0xf131b5('0x35')]&&(_0x473323[_0xf131b5('0xc')]=[{'all':!![]}]),_0x473323=_[_0xf131b5('0x53')]({},_0x473323,_0x5f02e9[_0xf131b5('0x31')]),db[_0xf131b5('0x58')][_0xf131b5('0x4b')](_0x473323)['then'](handleEntityNotFound(_0x4cfc21,null))[_0xf131b5('0x2')](respondWithResult(_0x4cfc21,null))[_0xf131b5('0x17')](handleError(_0x4cfc21,null));},exports[_0x2529f4('0x52')]=function(_0x115152,_0x3021bd){const _0x65db48=_0x2529f4;let _0x2d08df={'where':{'id':_0x115152[_0x65db48('0x1a')]['id']}};const _0x325153={};return _0x325153['model']=_[_0x65db48('0x42')](db['Trunk'][_0x65db48('0x30')]),_0x2d08df[_0x65db48('0x38')]=_[_0x65db48('0x5a')](_0x325153['model'],qs[_0x65db48('0x3b')](_0x115152[_0x65db48('0x22')][_0x65db48('0x3b')])),_0x2d08df[_0x65db48('0x38')]=_0x2d08df['attributes'][_0x65db48('0x1c')]?_0x2d08df[_0x65db48('0x38')]:_0x325153[_0x65db48('0x0')],_0x115152[_0x65db48('0x22')][_0x65db48('0x35')]&&(_0x2d08df[_0x65db48('0xc')]=[{'all':!![]}]),_0x2d08df=_['merge']({},_0x2d08df,_0x115152[_0x65db48('0x31')]),db['Trunk'][_0x65db48('0x4b')](_0x2d08df)[_0x65db48('0x2')](handleEntityNotFound(_0x3021bd,null))[_0x65db48('0x2')](function(_0x150249){const _0x4122c5=_0x65db48;if(_0x150249){let _0x5e6a9c=_0x150249[_0x4122c5('0x4e')]({'plain':!![]});return _0x5e6a9c=qs[_0x4122c5('0x39')](_0x5e6a9c,['id',_0x4122c5('0x2a'),_0x4122c5('0x2f')]),_0x115152['body']=_['omit'](_0x115152[_0x4122c5('0x5b')],['id',_0x4122c5('0x2a'),_0x4122c5('0x2f')]),db[_0x4122c5('0x58')]['create'](_['merge'](_0x5e6a9c,_0x115152[_0x4122c5('0x5b')]),{'include':_0x115152[_0x4122c5('0x22')]['includeAll']?[{'all':!![]}]:undefined})['then'](function(_0xa7cb87){const _0x3acf01=_0x4122c5,_0x525ad1=_0x115152[_0x3acf01('0x2c')]['get']({'plain':!![]});if(!_0x525ad1)throw new Error(_0x3acf01('0x3d'));if(_0x525ad1[_0x3acf01('0xf')]==='user'){const _0x9d0a48=_0xa7cb87[_0x3acf01('0x4e')]({'plain':!![]}),_0x435f4b=_0x3acf01('0x56');return db['UserProfileSection']['findOne']({'where':{'name':_0x435f4b,'userProfileId':_0x525ad1[_0x3acf01('0x1b')]},'raw':!![]})['then'](function(_0x52cc8b){const _0xe08157=_0x3acf01;return _0x52cc8b&&_0x52cc8b[_0xe08157('0xd')]===0x0?db[_0xe08157('0x24')][_0xe08157('0x6')]({'name':_0x9d0a48[_0xe08157('0x49')],'resourceId':_0x9d0a48['id'],'type':_0x52cc8b[_0xe08157('0x49')],'sectionId':_0x52cc8b['id']},{})[_0xe08157('0x2')](function(){return _0xa7cb87;}):_0xa7cb87;})[_0x3acf01('0x17')](function(_0x2e17ef){const _0x1aade3=_0x3acf01;logger[_0x1aade3('0x55')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2e17ef);throw _0x2e17ef;});}return _0xa7cb87;});}})[_0x65db48('0x2')](respondWithResult(_0x3021bd,0xc9))['catch'](handleError(_0x3021bd,null));},exports['create']=function(_0x2060f5,_0x23c877){const _0x147f1f=_0x2529f4;let _0x4dc5aa;return db[_0x147f1f('0x58')][_0x147f1f('0x6')](_0x2060f5[_0x147f1f('0x5b')],{'raw':!![]})['then'](function(_0x1d3b9f){const _0x1fc6e3=_0x147f1f;return _0x4dc5aa=_0x1d3b9f,db[_0x1fc6e3('0x58')][_0x1fc6e3('0x43')]({'raw':!![]});})[_0x147f1f('0x2')](function(_0x2e0ee1){const _0x501d33=_0x147f1f,_0x766d50=fs[_0x501d33('0x33')](path[_0x501d33('0x40')](config[_0x501d33('0x36')],_0x501d33('0x4')),_0x501d33('0x13')),_0x9895d3=fs[_0x501d33('0x33')](path[_0x501d33('0x40')](config[_0x501d33('0x36')],_0x501d33('0x3')),_0x501d33('0x13')),_0x1094f0=ejs[_0x501d33('0x19')](_0x766d50,{'trunks':_0x2e0ee1||[]});fs[_0x501d33('0x8')](_0x501d33('0x4f'),_0x1094f0);if(_0x4dc5aa[_0x501d33('0x1f')]){const _0x5043f0=ejs['render'](_0x9895d3,{'trunks':_0x2e0ee1||[]});fs[_0x501d33('0x8')](_0x501d33('0x59'),_0x5043f0);}})['then'](function(){const _0x57405e=_0x147f1f;return respondWithRpcPromise(_0x57405e('0x25'),_0x57405e('0x6'),{'module':_0x57405e('0x2e')});})[_0x147f1f('0x2')](function(){const _0x3e5d5a=_0x147f1f,_0x334e57=_0x2060f5[_0x3e5d5a('0x2c')]['get']({'plain':!![]});if(!_0x334e57)throw new Error(_0x3e5d5a('0x3d'));if(_0x334e57[_0x3e5d5a('0xf')]==='user'){const _0x3956f0=_0x4dc5aa[_0x3e5d5a('0x4e')]({'plain':!![]});return db[_0x3e5d5a('0x2d')]['findOne']({'where':{'name':_0x3e5d5a('0x56'),'userProfileId':_0x334e57[_0x3e5d5a('0x1b')]},'raw':!![]})[_0x3e5d5a('0x2')](function(_0x2ad886){const _0x558fd4=_0x3e5d5a;return _0x2ad886&&_0x2ad886[_0x558fd4('0xd')]===0x0?db[_0x558fd4('0x24')][_0x558fd4('0x6')]({'name':_0x3956f0[_0x558fd4('0x49')],'resourceId':_0x3956f0['id'],'type':_0x2ad886[_0x558fd4('0x49')],'sectionId':_0x2ad886['id']},{})['then'](function(){return _0x4dc5aa;}):_0x4dc5aa;})[_0x3e5d5a('0x17')](function(_0x20a87d){const _0x4bc72f=_0x3e5d5a;logger[_0x4bc72f('0x55')](_0x4bc72f('0x41'),_0x20a87d);throw _0x20a87d;});}return _0x4dc5aa;})[_0x147f1f('0x2')](respondWithResult(_0x23c877,0xc9))[_0x147f1f('0x17')](handleError(_0x23c877,null));},exports[_0x2529f4('0x29')]=function(_0x574bcb,_0xbffb5c){const _0x50d3c7=_0x2529f4;let _0x51e8c2;return db[_0x50d3c7('0x58')]['findOne']({'where':{'id':_0x574bcb[_0x50d3c7('0x1a')]['id']}})['then'](handleEntityNotFound(_0xbffb5c,null))[_0x50d3c7('0x2')](saveUpdates(_0x574bcb[_0x50d3c7('0x5b')],null))[_0x50d3c7('0x2')](function(_0x5ec773){const _0x42e1e8=_0x50d3c7;if(_0x5ec773)return _0x51e8c2=_0x5ec773,db[_0x42e1e8('0x58')]['findAll']({'raw':!![]});})[_0x50d3c7('0x2')](function(_0x4413e7){const _0x148aaa=_0x50d3c7;if(_0x4413e7){const _0x5b4dcc=fs['readFileSync'](path[_0x148aaa('0x40')](config[_0x148aaa('0x36')],_0x148aaa('0x4')),_0x148aaa('0x13')),_0x550d79=fs[_0x148aaa('0x33')](path[_0x148aaa('0x40')](config['root'],'files/templates/registry.ejs'),_0x148aaa('0x13')),_0xb51511=ejs[_0x148aaa('0x19')](_0x5b4dcc,{'trunks':_0x4413e7||[]});fs['writeFileSync'](_0x148aaa('0x4f'),_0xb51511);const _0x1c51de=ejs[_0x148aaa('0x19')](_0x550d79,{'trunks':_0x4413e7||[]});return fs[_0x148aaa('0x8')](_0x148aaa('0x59'),_0x1c51de),respondWithRpcPromise(_0x148aaa('0x25'),_0x148aaa('0x29'),{'module':_0x148aaa('0x2e')});}return null;})['then'](function(_0x1f5bfd){if(_0x1f5bfd)return _0x51e8c2;})[_0x50d3c7('0x2')](respondWithResult(_0xbffb5c,null))[_0x50d3c7('0x17')](handleError(_0xbffb5c,null));},exports[_0x2529f4('0x18')]=function(_0x2f2a26,_0x2eeec9){const _0x43aa94=_0x2529f4;return db[_0x43aa94('0x58')][_0x43aa94('0x4b')]({'where':{'id':_0x2f2a26[_0x43aa94('0x1a')]['id']}})['then'](handleEntityNotFound(_0x2eeec9,null))['then'](removeEntity(_0x2eeec9,null))[_0x43aa94('0x2')](function(){const _0x18efcf=_0x43aa94;return db['Trunk'][_0x18efcf('0x43')]({'raw':!![]});})[_0x43aa94('0x2')](function(_0x37b29a){const _0x3ab1f7=_0x43aa94,_0x1adcbe=fs['readFileSync'](path[_0x3ab1f7('0x40')](config['root'],_0x3ab1f7('0x4')),_0x3ab1f7('0x13')),_0xe77679=fs['readFileSync'](path[_0x3ab1f7('0x40')](config[_0x3ab1f7('0x36')],_0x3ab1f7('0x3')),'utf8'),_0x18c651=ejs[_0x3ab1f7('0x19')](_0x1adcbe,{'trunks':_0x37b29a}),_0x4550f6=ejs[_0x3ab1f7('0x19')](_0xe77679,{'trunks':_0x37b29a});return fs[_0x3ab1f7('0x8')](_0x3ab1f7('0x4f'),_0x18c651),fs[_0x3ab1f7('0x8')](_0x3ab1f7('0x59'),_0x4550f6),respondWithRpcPromise('Reload',_0x3ab1f7('0x18'),{'module':_0x3ab1f7('0x2e')});})[_0x43aa94('0x17')](handleError(_0x2eeec9,null));};