Built motion from commit f738f9592c388b9f9eb3948f400a5c9d717a3561. Version 3.0.0...
[motion-next.git] / server / api / trunk / trunk.controller.js
index df29a32..8832bc3 100644 (file)
@@ -1 +1 @@
-const a769_0x29c6=['sendStatus','set','join','render','userProfileId','stringify','filter','destroy','UserProfileResource','registry','then','request','order','../../components/parsers/qs','include','intersection','Trunk,\x20%s,\x20%s,\x20%s','Content-Range','body','fields','UserProfileSection','type','../../config/logger','update','/etc/asterisk/sip_xcally_registers.conf','count','files/templates/trunk.ejs','end','findAll','code','role','filters','map','options','status','offset','message','length','autoAssociation','findOne','readFileSync','model','catch','jayson/promise','sort','clone','chan_sip.so','Reload','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','files/templates/registry.ejs','utf8','request\x20sent','stack','info','../../mysqldb','limit','Unable\x20to\x20retrieve\x20the\x20current\x20user','rawAttributes','fieldName','keys','Trunks','ejs','attributes','createdAt','show','VIRTUAL','user','updatedAt','Trunk','writeFileSync','includeAll','rows','get','create','send','name','../../config/environment','error','like','merge','nolimit','/etc/asterisk/sip_xcally_trunks.conf','query','params','sequelize','undefined','json','pick','root','omit','where','Trunk,\x20%s,\x20%s'];(function(_0x35a9b2,_0x239325){const _0x29c6f8=function(_0x2f4c4c){while(--_0x2f4c4c){_0x35a9b2['push'](_0x35a9b2['shift']());}};_0x29c6f8(++_0x239325);}(a769_0x29c6,0x13b));const a769_0x2f4c=function(_0x35a9b2,_0x239325){_0x35a9b2=_0x35a9b2-0x1b7;let _0x29c6f8=a769_0x29c6[_0x35a9b2];return _0x29c6f8;};const a769_0x5b804b=a769_0x2f4c;'use strict';const path=require('path'),ejs=require(a769_0x5b804b(0x1cd)),fs=require('fs'),_=require('lodash'),qs=require(a769_0x5b804b(0x1f9)),logger=require(a769_0x5b804b(0x202))('api'),config=require(a769_0x5b804b(0x1dc)),{db}=require(a769_0x5b804b(0x1c6)),{Op}=require(a769_0x5b804b(0x1e4)),jayson=require(a769_0x5b804b(0x1bb)),client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x1341cd,_0x4e2434,_0x1cf9a1,_0x551f23){return new Promise(function(_0x4ebb31,_0x50d497){const _0x5c0644=a769_0x2f4c,_0x363db5=_0x551f23||client;return _0x363db5[_0x5c0644(0x1f7)](_0x1341cd,_0x1cf9a1)['then'](function(_0x29847c){const _0x5bf097=_0x5c0644;logger[_0x5bf097(0x1c5)]('Trunk,\x20%s,\x20%s',_0x4e2434,_0x5bf097(0x1c3)),logger['debug'](_0x5bf097(0x1fc),_0x4e2434,_0x5bf097(0x1c3),JSON[_0x5bf097(0x1f1)](_0x29847c));if(_0x29847c['error']){if(_0x29847c[_0x5bf097(0x1dd)][_0x5bf097(0x209)]===0x1f4)return logger[_0x5bf097(0x1dd)](_0x5bf097(0x1eb),_0x4e2434,_0x29847c['error'][_0x5bf097(0x210)]),_0x50d497(_0x29847c[_0x5bf097(0x1dd)][_0x5bf097(0x210)]);return logger[_0x5bf097(0x1dd)](_0x5bf097(0x1eb),_0x4e2434,_0x29847c[_0x5bf097(0x1dd)][_0x5bf097(0x210)]),_0x4ebb31(_0x29847c[_0x5bf097(0x1dd)]['message']);}else logger[_0x5bf097(0x1c5)]('Trunk,\x20%s,\x20%s',_0x4e2434,_0x5bf097(0x1c3)),_0x4ebb31(_0x29847c['result'][_0x5bf097(0x210)]);})[_0x5c0644(0x1ba)](function(_0x22779c){const _0x1cd051=_0x5c0644;logger[_0x1cd051(0x1dd)](_0x1cd051(0x1eb),_0x4e2434,_0x22779c),_0x50d497(_0x22779c);});});}function respondWithResult(_0x3ea357,_0x55e3ae){return _0x55e3ae=_0x55e3ae||0xc8,function(_0x16a384){const _0x2157a3=a769_0x2f4c;if(_0x16a384)return _0x3ea357[_0x2157a3(0x20e)](_0x55e3ae)['json'](_0x16a384);};}function respondWithFilteredResult(_0x4aa8b7,_0x5712e8){return function(_0x31a84a){const _0x3d2b70=a769_0x2f4c;if(_0x31a84a){const _0x3d198a=_0x31a84a[_0x3d2b70(0x205)],_0x46e438=_0x5712e8['offset'];let _0x23e6ab=_0x5712e8[_0x3d2b70(0x20f)]+_0x5712e8[_0x3d2b70(0x1c7)],_0x4e22e7;return _0x23e6ab>=_0x3d198a?(_0x23e6ab=_0x3d198a,_0x4e22e7=0xc8):_0x4e22e7=0xce,_0x4aa8b7[_0x3d2b70(0x20e)](_0x4e22e7),_0x4aa8b7[_0x3d2b70(0x1ed)](_0x3d2b70(0x1fd),_0x46e438+'-'+_0x23e6ab+'/'+_0x3d198a)[_0x3d2b70(0x1e6)](_0x31a84a);}return null;};}function saveUpdates(_0x50df3b){return function(_0x126a40){const _0x26cbb2=a769_0x2f4c;if(_0x126a40)return _0x126a40[_0x26cbb2(0x203)](_0x50df3b)[_0x26cbb2(0x1f6)](function(_0x42c315){return _0x42c315;});return null;};}function removeEntity(_0x105965){return function(_0x213411){const _0x4273bd=a769_0x2f4c;if(_0x213411)return _0x213411[_0x4273bd(0x1f3)]()[_0x4273bd(0x1f6)](function(){const _0x1a2aaa=_0x4273bd,_0x1d903a=_0x213411[_0x1a2aaa(0x1d8)]({'plain':!![]}),_0x13a33e=_0x1a2aaa(0x1cc);return db[_0x1a2aaa(0x1f4)][_0x1a2aaa(0x1f3)]({'where':{'type':_0x13a33e,'resourceId':_0x1d903a['id']}})[_0x1a2aaa(0x1f6)](function(){return _0x213411;});})[_0x4273bd(0x1f6)](function(){const _0x55d6e7=_0x4273bd;_0x105965[_0x55d6e7(0x20e)](0xcc)[_0x55d6e7(0x207)]();});};}function handleEntityNotFound(_0xb85abe){return function(_0x48d4ae){const _0x3a31c7=a769_0x2f4c;return!_0x48d4ae&&_0xb85abe[_0x3a31c7(0x1ec)](0x194),_0x48d4ae;};}function handleError(_0x558a70,_0x5ebb4e){return _0x5ebb4e=_0x5ebb4e||0x1f4,function(_0x52fd3f){const _0x56464f=a769_0x2f4c;logger['error'](_0x52fd3f[_0x56464f(0x1c4)]),_0x52fd3f[_0x56464f(0x1db)]&&delete _0x52fd3f[_0x56464f(0x1db)],_0x558a70[_0x56464f(0x20e)](_0x5ebb4e)[_0x56464f(0x1da)](_0x52fd3f);};}exports['index']=function(_0x5c8d14,_0x4a5f4b){const _0x6080e=a769_0x5b804b;let _0x57c0fe={};const _0x5df355={},_0x1913f7={'count':0x0,'rows':[]},_0x503c17=_[_0x6080e(0x20c)](db['Trunk'][_0x6080e(0x1c9)],function(_0x1d15a1){const _0x408e2a=_0x6080e;return{'name':_0x1d15a1[_0x408e2a(0x1ca)],'type':_0x1d15a1[_0x408e2a(0x201)]['key']};});_0x5df355[_0x6080e(0x1b9)]=_[_0x6080e(0x20c)](_0x503c17,_0x6080e(0x1db)),_0x5df355[_0x6080e(0x1e2)]=_[_0x6080e(0x1cb)](_0x5c8d14['query']),_0x5df355[_0x6080e(0x20b)]=_[_0x6080e(0x1fb)](_0x5df355[_0x6080e(0x1b9)],_0x5df355['query']),_0x57c0fe[_0x6080e(0x1ce)]=_[_0x6080e(0x1fb)](_0x5df355[_0x6080e(0x1b9)],qs['fields'](_0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x1ff)])),_0x57c0fe[_0x6080e(0x1ce)]=_0x57c0fe[_0x6080e(0x1ce)]['length']?_0x57c0fe[_0x6080e(0x1ce)]:_0x5df355['model'];typeof _0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x1e0)]===_0x6080e(0x1e5)&&(_0x57c0fe['limit']=qs['limit'](_0x5c8d14['query'][_0x6080e(0x1c7)]),_0x57c0fe[_0x6080e(0x20f)]=qs[_0x6080e(0x20f)](_0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x20f)]));_0x57c0fe[_0x6080e(0x1f8)]=qs[_0x6080e(0x1bc)](_0x5c8d14[_0x6080e(0x1e2)]['sort']),_0x57c0fe['where']=qs[_0x6080e(0x20b)](_[_0x6080e(0x1e7)](_0x5c8d14[_0x6080e(0x1e2)],_0x5df355[_0x6080e(0x20b)]),_0x503c17);_0x5c8d14[_0x6080e(0x1e2)][_0x6080e(0x1f2)]&&(_0x57c0fe[_0x6080e(0x1ea)]=_[_0x6080e(0x1df)](_0x57c0fe[_0x6080e(0x1ea)],{[Op['or']]:_[_0x6080e(0x20c)](_0x503c17,function(_0x209974){const _0x9e471d=_0x6080e;if(_0x209974[_0x9e471d(0x201)]!==_0x9e471d(0x1d1)){const _0x194f0c={};return _0x194f0c[_0x209974[_0x9e471d(0x1db)]]={[Op[_0x9e471d(0x1de)]]:'%'+_0x5c8d14[_0x9e471d(0x1e2)][_0x9e471d(0x1f2)]+'%'},_0x194f0c;}})}));_0x57c0fe=_['merge']({},_0x57c0fe,_0x5c8d14['options']);const _0x20d966={'where':_0x57c0fe[_0x6080e(0x1ea)]};return db['Trunk'][_0x6080e(0x205)](_0x20d966)[_0x6080e(0x1f6)](function(_0x460fe5){const _0x40e443=_0x6080e;return _0x1913f7[_0x40e443(0x205)]=_0x460fe5,_0x5c8d14[_0x40e443(0x1e2)]['includeAll']&&(_0x57c0fe[_0x40e443(0x1fa)]=[{'all':!![]}]),db['Trunk'][_0x40e443(0x208)](_0x57c0fe);})[_0x6080e(0x1f6)](function(_0x46df94){const _0x7ce4b6=_0x6080e;return _0x1913f7[_0x7ce4b6(0x1d7)]=_0x46df94,_0x1913f7;})[_0x6080e(0x1f6)](respondWithFilteredResult(_0x4a5f4b,_0x57c0fe))[_0x6080e(0x1ba)](handleError(_0x4a5f4b,null));},exports[a769_0x5b804b(0x1d0)]=function(_0x5e5997,_0xb5c740){const _0x3ae169=a769_0x5b804b;let _0x43321d={'raw':![],'where':{'id':_0x5e5997[_0x3ae169(0x1e3)]['id']}};const _0x298d16={};return _0x298d16[_0x3ae169(0x1b9)]=_[_0x3ae169(0x1cb)](db[_0x3ae169(0x1d4)]['rawAttributes']),_0x298d16[_0x3ae169(0x1e2)]=_[_0x3ae169(0x1cb)](_0x5e5997[_0x3ae169(0x1e2)]),_0x298d16[_0x3ae169(0x20b)]=_[_0x3ae169(0x1fb)](_0x298d16['model'],_0x298d16['query']),_0x43321d['attributes']=_[_0x3ae169(0x1fb)](_0x298d16[_0x3ae169(0x1b9)],qs[_0x3ae169(0x1ff)](_0x5e5997[_0x3ae169(0x1e2)]['fields'])),_0x43321d['attributes']=_0x43321d[_0x3ae169(0x1ce)][_0x3ae169(0x211)]?_0x43321d['attributes']:_0x298d16['model'],_0x5e5997['query'][_0x3ae169(0x1d6)]&&(_0x43321d[_0x3ae169(0x1fa)]=[{'all':!![]}]),_0x43321d=_[_0x3ae169(0x1df)]({},_0x43321d,_0x5e5997[_0x3ae169(0x20d)]),db[_0x3ae169(0x1d4)]['findOne'](_0x43321d)[_0x3ae169(0x1f6)](handleEntityNotFound(_0xb5c740,null))[_0x3ae169(0x1f6)](respondWithResult(_0xb5c740,null))['catch'](handleError(_0xb5c740,null));},exports[a769_0x5b804b(0x1bd)]=function(_0x217c3d,_0x5dd742){const _0xbe6980=a769_0x5b804b;let _0x16a255={'where':{'id':_0x217c3d[_0xbe6980(0x1e3)]['id']}};const _0xef57c={};return _0xef57c[_0xbe6980(0x1b9)]=_[_0xbe6980(0x1cb)](db[_0xbe6980(0x1d4)][_0xbe6980(0x1c9)]),_0x16a255[_0xbe6980(0x1ce)]=_['intersection'](_0xef57c[_0xbe6980(0x1b9)],qs[_0xbe6980(0x1ff)](_0x217c3d[_0xbe6980(0x1e2)]['fields'])),_0x16a255['attributes']=_0x16a255[_0xbe6980(0x1ce)][_0xbe6980(0x211)]?_0x16a255[_0xbe6980(0x1ce)]:_0xef57c[_0xbe6980(0x1b9)],_0x217c3d['query'][_0xbe6980(0x1d6)]&&(_0x16a255[_0xbe6980(0x1fa)]=[{'all':!![]}]),_0x16a255=_['merge']({},_0x16a255,_0x217c3d[_0xbe6980(0x20d)]),db[_0xbe6980(0x1d4)]['findOne'](_0x16a255)[_0xbe6980(0x1f6)](handleEntityNotFound(_0x5dd742,null))['then'](function(_0x16fdc4){const _0x5c999d=_0xbe6980;if(_0x16fdc4){let _0x40a4ee=_0x16fdc4[_0x5c999d(0x1d8)]({'plain':!![]});return _0x40a4ee=qs[_0x5c999d(0x1e9)](_0x40a4ee,['id','createdAt',_0x5c999d(0x1d3)]),_0x217c3d[_0x5c999d(0x1fe)]=_[_0x5c999d(0x1e9)](_0x217c3d[_0x5c999d(0x1fe)],['id',_0x5c999d(0x1cf),'updatedAt']),db[_0x5c999d(0x1d4)][_0x5c999d(0x1d9)](_[_0x5c999d(0x1df)](_0x40a4ee,_0x217c3d[_0x5c999d(0x1fe)]),{'include':_0x217c3d[_0x5c999d(0x1e2)][_0x5c999d(0x1d6)]?[{'all':!![]}]:undefined})[_0x5c999d(0x1f6)](function(_0x53d73f){const _0x4060f3=_0x5c999d,_0x10f43b=_0x217c3d[_0x4060f3(0x1d2)]['get']({'plain':!![]});if(!_0x10f43b)throw new Error(_0x4060f3(0x1c8));if(_0x10f43b[_0x4060f3(0x20a)]===_0x4060f3(0x1d2)){const _0x15a961=_0x53d73f[_0x4060f3(0x1d8)]({'plain':!![]}),_0x5883ae=_0x4060f3(0x1cc);return db[_0x4060f3(0x200)][_0x4060f3(0x1b7)]({'where':{'name':_0x5883ae,'userProfileId':_0x10f43b[_0x4060f3(0x1f0)]},'raw':!![]})[_0x4060f3(0x1f6)](function(_0xd242b5){const _0x5b9e23=_0x4060f3;return _0xd242b5&&_0xd242b5[_0x5b9e23(0x212)]===0x0?db[_0x5b9e23(0x1f4)][_0x5b9e23(0x1d9)]({'name':_0x15a961[_0x5b9e23(0x1db)],'resourceId':_0x15a961['id'],'type':_0xd242b5['name'],'sectionId':_0xd242b5['id']},{})['then'](function(){return _0x53d73f;}):_0x53d73f;})[_0x4060f3(0x1ba)](function(_0x11cd84){const _0x21b0ee=_0x4060f3;logger[_0x21b0ee(0x1dd)](_0x21b0ee(0x1c0),_0x11cd84);throw _0x11cd84;});}return _0x53d73f;});}})[_0xbe6980(0x1f6)](respondWithResult(_0x5dd742,0xc9))[_0xbe6980(0x1ba)](handleError(_0x5dd742,null));},exports[a769_0x5b804b(0x1d9)]=function(_0x1b4a35,_0x427026){const _0x11abd3=a769_0x5b804b;let _0x15b41a;return db[_0x11abd3(0x1d4)][_0x11abd3(0x1d9)](_0x1b4a35[_0x11abd3(0x1fe)],{'raw':!![]})[_0x11abd3(0x1f6)](function(_0x823ab7){const _0x212350=_0x11abd3;return _0x15b41a=_0x823ab7,db[_0x212350(0x1d4)]['findAll']({'raw':!![]});})['then'](function(_0x213ebb){const _0x4febf9=_0x11abd3,_0x4b2835=fs[_0x4febf9(0x1b8)](path[_0x4febf9(0x1ee)](config[_0x4febf9(0x1e8)],'files/templates/trunk.ejs'),'utf8'),_0x408a49=fs[_0x4febf9(0x1b8)](path[_0x4febf9(0x1ee)](config[_0x4febf9(0x1e8)],_0x4febf9(0x1c1)),'utf8'),_0x5c2f48=ejs[_0x4febf9(0x1ef)](_0x4b2835,{'trunks':_0x213ebb||[]});fs[_0x4febf9(0x1d5)](_0x4febf9(0x1e1),_0x5c2f48);if(_0x15b41a[_0x4febf9(0x1f5)]){const _0xb2fe3c=ejs[_0x4febf9(0x1ef)](_0x408a49,{'trunks':_0x213ebb||[]});fs[_0x4febf9(0x1d5)](_0x4febf9(0x204),_0xb2fe3c);}})[_0x11abd3(0x1f6)](function(){const _0xc2718a=_0x11abd3;return respondWithRpcPromise(_0xc2718a(0x1bf),_0xc2718a(0x1d9),{'module':'chan_sip.so'});})[_0x11abd3(0x1f6)](function(){const _0x432ece=_0x11abd3,_0x5433fc=_0x1b4a35[_0x432ece(0x1d2)][_0x432ece(0x1d8)]({'plain':!![]});if(!_0x5433fc)throw new Error(_0x432ece(0x1c8));if(_0x5433fc['role']==='user'){const _0x32465c=_0x15b41a[_0x432ece(0x1d8)]({'plain':!![]});return db[_0x432ece(0x200)]['findOne']({'where':{'name':_0x432ece(0x1cc),'userProfileId':_0x5433fc[_0x432ece(0x1f0)]},'raw':!![]})['then'](function(_0x583780){const _0x4cb3ec=_0x432ece;return _0x583780&&_0x583780[_0x4cb3ec(0x212)]===0x0?db[_0x4cb3ec(0x1f4)]['create']({'name':_0x32465c[_0x4cb3ec(0x1db)],'resourceId':_0x32465c['id'],'type':_0x583780['name'],'sectionId':_0x583780['id']},{})['then'](function(){return _0x15b41a;}):_0x15b41a;})['catch'](function(_0x223dbd){const _0x46433e=_0x432ece;logger[_0x46433e(0x1dd)](_0x46433e(0x1c0),_0x223dbd);throw _0x223dbd;});}return _0x15b41a;})['then'](respondWithResult(_0x427026,0xc9))[_0x11abd3(0x1ba)](handleError(_0x427026,null));},exports[a769_0x5b804b(0x203)]=function(_0x27c638,_0x2e3b44){const _0x32a757=a769_0x5b804b;let _0x187a6f;return db[_0x32a757(0x1d4)][_0x32a757(0x1b7)]({'where':{'id':_0x27c638[_0x32a757(0x1e3)]['id']}})[_0x32a757(0x1f6)](handleEntityNotFound(_0x2e3b44,null))['then'](saveUpdates(_0x27c638[_0x32a757(0x1fe)],null))[_0x32a757(0x1f6)](function(_0x2009fc){if(_0x2009fc)return _0x187a6f=_0x2009fc,db['Trunk']['findAll']({'raw':!![]});})[_0x32a757(0x1f6)](function(_0x40ff83){const _0x94b9b2=_0x32a757;if(_0x40ff83){const _0x2e929b=fs[_0x94b9b2(0x1b8)](path[_0x94b9b2(0x1ee)](config[_0x94b9b2(0x1e8)],'files/templates/trunk.ejs'),_0x94b9b2(0x1c2)),_0x5c19af=fs[_0x94b9b2(0x1b8)](path[_0x94b9b2(0x1ee)](config['root'],'files/templates/registry.ejs'),'utf8'),_0x4ba687=ejs[_0x94b9b2(0x1ef)](_0x2e929b,{'trunks':_0x40ff83||[]});fs[_0x94b9b2(0x1d5)]('/etc/asterisk/sip_xcally_trunks.conf',_0x4ba687);const _0x51feb8=ejs['render'](_0x5c19af,{'trunks':_0x40ff83||[]});return fs[_0x94b9b2(0x1d5)](_0x94b9b2(0x204),_0x51feb8),respondWithRpcPromise(_0x94b9b2(0x1bf),_0x94b9b2(0x203),{'module':_0x94b9b2(0x1be)});}return null;})[_0x32a757(0x1f6)](function(_0x5e4c36){if(_0x5e4c36)return _0x187a6f;})[_0x32a757(0x1f6)](respondWithResult(_0x2e3b44,null))[_0x32a757(0x1ba)](handleError(_0x2e3b44,null));},exports[a769_0x5b804b(0x1f3)]=function(_0x37cc37,_0x2aa630){const _0x56d1f2=a769_0x5b804b;return db[_0x56d1f2(0x1d4)][_0x56d1f2(0x1b7)]({'where':{'id':_0x37cc37[_0x56d1f2(0x1e3)]['id']}})[_0x56d1f2(0x1f6)](handleEntityNotFound(_0x2aa630,null))[_0x56d1f2(0x1f6)](removeEntity(_0x2aa630,null))[_0x56d1f2(0x1f6)](function(){const _0x5ccdfe=_0x56d1f2;return db['Trunk'][_0x5ccdfe(0x208)]({'raw':!![]});})[_0x56d1f2(0x1f6)](function(_0x22517b){const _0xe8dc78=_0x56d1f2,_0x3be8f9=fs[_0xe8dc78(0x1b8)](path[_0xe8dc78(0x1ee)](config['root'],_0xe8dc78(0x206)),_0xe8dc78(0x1c2)),_0x5d5384=fs[_0xe8dc78(0x1b8)](path[_0xe8dc78(0x1ee)](config[_0xe8dc78(0x1e8)],_0xe8dc78(0x1c1)),_0xe8dc78(0x1c2)),_0xb7553c=ejs[_0xe8dc78(0x1ef)](_0x3be8f9,{'trunks':_0x22517b}),_0x4a93f9=ejs['render'](_0x5d5384,{'trunks':_0x22517b});return fs[_0xe8dc78(0x1d5)](_0xe8dc78(0x1e1),_0xb7553c),fs['writeFileSync']('/etc/asterisk/sip_xcally_registers.conf',_0x4a93f9),respondWithRpcPromise(_0xe8dc78(0x1bf),_0xe8dc78(0x1f3),{'module':_0xe8dc78(0x1be)});})[_0x56d1f2(0x1ba)](handleError(_0x2aa630,null));};
\ No newline at end of file
+const a769_0x4b9b=['info','findAll','lodash','type','like','render','rawAttributes','message','files/templates/registry.ejs','createdAt','files/templates/trunk.ejs','end','userProfileId','ejs','VIRTUAL','json','code','updatedAt','UserProfileResource','role','readFileSync','then','key','omit','undefined','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','query','create','findOne','registry','set','fieldName','nolimit','utf8','request','params','count','update','sequelize','pick','includeAll','writeFileSync','result','chan_sip.so','sort','map','keys','/etc/asterisk/sip_xcally_registers.conf','filters','error','index','UserProfileSection','../../config/environment','root','/etc/asterisk/sip_xcally_trunks.conf','get','model','Content-Range','status','body','debug','merge','Unable\x20to\x20retrieve\x20the\x20current\x20user','stack','user','Trunk','Reload','length','destroy','stringify','http','autoAssociation','catch','limit','../../config/logger','../../components/parsers/qs','include','Trunk,\x20%s,\x20%s','attributes','filter','join','Trunk,\x20%s,\x20%s,\x20%s','offset','path','client','fields','name','request\x20sent','intersection','options','Trunks','where'];(function(_0x305aa5,_0x551112){const _0x4b9b3a=function(_0x369cf5){while(--_0x369cf5){_0x305aa5['push'](_0x305aa5['shift']());}};_0x4b9b3a(++_0x551112);}(a769_0x4b9b,0x134));const a769_0x369c=function(_0x305aa5,_0x551112){_0x305aa5=_0x305aa5-0x14b;let _0x4b9b3a=a769_0x4b9b[_0x305aa5];return _0x4b9b3a;};const a769_0x1ea04a=a769_0x369c;'use strict';const path=require(a769_0x1ea04a(0x17e)),ejs=require(a769_0x1ea04a(0x194)),fs=require('fs'),_=require(a769_0x1ea04a(0x189)),qs=require(a769_0x1ea04a(0x176)),logger=require(a769_0x1ea04a(0x175))('api'),config=require(a769_0x1ea04a(0x15f)),{db}=require('../../mysqldb'),{Op}=require(a769_0x1ea04a(0x151)),jayson=require('jayson/promise'),client=jayson[a769_0x1ea04a(0x17f)][a769_0x1ea04a(0x171)]({'port':0x232a});function respondWithRpcPromise(_0x4fc1f0,_0x3c204d,_0x51c1bb,_0x1c0f2b){return new Promise(function(_0x307a57,_0x3f04e9){const _0x554d1a=a769_0x369c,_0x5574c3=_0x1c0f2b||client;return _0x5574c3[_0x554d1a(0x14d)](_0x4fc1f0,_0x51c1bb)[_0x554d1a(0x19c)](function(_0x2662ff){const _0x1e348b=_0x554d1a;logger[_0x1e348b(0x187)](_0x1e348b(0x178),_0x3c204d,_0x1e348b(0x182)),logger[_0x1e348b(0x167)](_0x1e348b(0x17c),_0x3c204d,_0x1e348b(0x182),JSON[_0x1e348b(0x170)](_0x2662ff));if(_0x2662ff[_0x1e348b(0x15c)]){if(_0x2662ff[_0x1e348b(0x15c)][_0x1e348b(0x197)]===0x1f4)return logger[_0x1e348b(0x15c)](_0x1e348b(0x178),_0x3c204d,_0x2662ff[_0x1e348b(0x15c)][_0x1e348b(0x18e)]),_0x3f04e9(_0x2662ff['error'][_0x1e348b(0x18e)]);return logger[_0x1e348b(0x15c)]('Trunk,\x20%s,\x20%s',_0x3c204d,_0x2662ff[_0x1e348b(0x15c)][_0x1e348b(0x18e)]),_0x307a57(_0x2662ff[_0x1e348b(0x15c)][_0x1e348b(0x18e)]);}else logger['info']('Trunk,\x20%s,\x20%s',_0x3c204d,_0x1e348b(0x182)),_0x307a57(_0x2662ff[_0x1e348b(0x155)][_0x1e348b(0x18e)]);})['catch'](function(_0x4a0990){const _0x4550f4=_0x554d1a;logger[_0x4550f4(0x15c)](_0x4550f4(0x178),_0x3c204d,_0x4a0990),_0x3f04e9(_0x4a0990);});});}function respondWithResult(_0x54d654,_0x40a0f9){return _0x40a0f9=_0x40a0f9||0xc8,function(_0x249232){const _0x38613e=a769_0x369c;if(_0x249232)return _0x54d654[_0x38613e(0x165)](_0x40a0f9)['json'](_0x249232);};}function respondWithFilteredResult(_0x58765b,_0x3316e8){return function(_0x5d1f4f){const _0x44f70d=a769_0x369c;if(_0x5d1f4f){const _0x1a60f3=_0x5d1f4f['count'],_0x30d4ed=_0x3316e8[_0x44f70d(0x17d)];let _0x293480=_0x3316e8[_0x44f70d(0x17d)]+_0x3316e8[_0x44f70d(0x174)],_0x287cae;return _0x293480>=_0x1a60f3?(_0x293480=_0x1a60f3,_0x287cae=0xc8):_0x287cae=0xce,_0x58765b[_0x44f70d(0x165)](_0x287cae),_0x58765b[_0x44f70d(0x1a5)](_0x44f70d(0x164),_0x30d4ed+'-'+_0x293480+'/'+_0x1a60f3)[_0x44f70d(0x196)](_0x5d1f4f);}return null;};}function saveUpdates(_0x3a6080){return function(_0x2e03d9){const _0x1edcfc=a769_0x369c;if(_0x2e03d9)return _0x2e03d9[_0x1edcfc(0x150)](_0x3a6080)['then'](function(_0x1f43de){return _0x1f43de;});return null;};}function removeEntity(_0x15cf74){return function(_0x4aa995){const _0x2be7a1=a769_0x369c;if(_0x4aa995)return _0x4aa995[_0x2be7a1(0x16f)]()['then'](function(){const _0x43e960=_0x2be7a1,_0x4450de=_0x4aa995['get']({'plain':!![]}),_0x5d5f46='Trunks';return db[_0x43e960(0x199)][_0x43e960(0x16f)]({'where':{'type':_0x5d5f46,'resourceId':_0x4450de['id']}})[_0x43e960(0x19c)](function(){return _0x4aa995;});})[_0x2be7a1(0x19c)](function(){const _0x478dad=_0x2be7a1;_0x15cf74[_0x478dad(0x165)](0xcc)[_0x478dad(0x192)]();});};}function handleEntityNotFound(_0x595783){return function(_0x565657){return!_0x565657&&_0x595783['sendStatus'](0x194),_0x565657;};}function handleError(_0x4ea1c5,_0x2d5fbc){return _0x2d5fbc=_0x2d5fbc||0x1f4,function(_0x4fd4f0){const _0x49c682=a769_0x369c;logger[_0x49c682(0x15c)](_0x4fd4f0[_0x49c682(0x16a)]),_0x4fd4f0['name']&&delete _0x4fd4f0[_0x49c682(0x181)],_0x4ea1c5[_0x49c682(0x165)](_0x2d5fbc)['send'](_0x4fd4f0);};}exports[a769_0x1ea04a(0x15d)]=function(_0x479a1d,_0x2d8e34){const _0x2ac22d=a769_0x1ea04a;let _0x486865={};const _0x5b4561={},_0x333805={'count':0x0,'rows':[]},_0x5afd20=_['map'](db[_0x2ac22d(0x16c)]['rawAttributes'],function(_0x2540cd){const _0x278f34=_0x2ac22d;return{'name':_0x2540cd[_0x278f34(0x1a6)],'type':_0x2540cd['type'][_0x278f34(0x19d)]};});_0x5b4561[_0x2ac22d(0x163)]=_[_0x2ac22d(0x158)](_0x5afd20,_0x2ac22d(0x181)),_0x5b4561['query']=_['keys'](_0x479a1d[_0x2ac22d(0x1a1)]),_0x5b4561[_0x2ac22d(0x15b)]=_[_0x2ac22d(0x183)](_0x5b4561[_0x2ac22d(0x163)],_0x5b4561[_0x2ac22d(0x1a1)]),_0x486865[_0x2ac22d(0x179)]=_['intersection'](_0x5b4561[_0x2ac22d(0x163)],qs['fields'](_0x479a1d[_0x2ac22d(0x1a1)][_0x2ac22d(0x180)])),_0x486865[_0x2ac22d(0x179)]=_0x486865[_0x2ac22d(0x179)][_0x2ac22d(0x16e)]?_0x486865['attributes']:_0x5b4561[_0x2ac22d(0x163)];typeof _0x479a1d[_0x2ac22d(0x1a1)][_0x2ac22d(0x14b)]===_0x2ac22d(0x19f)&&(_0x486865[_0x2ac22d(0x174)]=qs[_0x2ac22d(0x174)](_0x479a1d[_0x2ac22d(0x1a1)][_0x2ac22d(0x174)]),_0x486865[_0x2ac22d(0x17d)]=qs[_0x2ac22d(0x17d)](_0x479a1d[_0x2ac22d(0x1a1)][_0x2ac22d(0x17d)]));_0x486865['order']=qs[_0x2ac22d(0x157)](_0x479a1d[_0x2ac22d(0x1a1)]['sort']),_0x486865[_0x2ac22d(0x186)]=qs['filters'](_[_0x2ac22d(0x152)](_0x479a1d['query'],_0x5b4561['filters']),_0x5afd20);_0x479a1d['query'][_0x2ac22d(0x17a)]&&(_0x486865['where']=_[_0x2ac22d(0x168)](_0x486865['where'],{[Op['or']]:_['map'](_0x5afd20,function(_0x36f7b9){const _0x137d24=_0x2ac22d;if(_0x36f7b9[_0x137d24(0x18a)]!==_0x137d24(0x195)){const _0x29a48c={};return _0x29a48c[_0x36f7b9[_0x137d24(0x181)]]={[Op[_0x137d24(0x18b)]]:'%'+_0x479a1d[_0x137d24(0x1a1)][_0x137d24(0x17a)]+'%'},_0x29a48c;}})}));_0x486865=_[_0x2ac22d(0x168)]({},_0x486865,_0x479a1d[_0x2ac22d(0x184)]);const _0x55ded9={'where':_0x486865[_0x2ac22d(0x186)]};return db['Trunk']['count'](_0x55ded9)[_0x2ac22d(0x19c)](function(_0x129929){const _0x571663=_0x2ac22d;return _0x333805[_0x571663(0x14f)]=_0x129929,_0x479a1d[_0x571663(0x1a1)]['includeAll']&&(_0x486865[_0x571663(0x177)]=[{'all':!![]}]),db[_0x571663(0x16c)][_0x571663(0x188)](_0x486865);})[_0x2ac22d(0x19c)](function(_0x59f60b){return _0x333805['rows']=_0x59f60b,_0x333805;})[_0x2ac22d(0x19c)](respondWithFilteredResult(_0x2d8e34,_0x486865))[_0x2ac22d(0x173)](handleError(_0x2d8e34,null));},exports['show']=function(_0x1299d1,_0x469768){const _0x13d9f7=a769_0x1ea04a;let _0x1743fe={'raw':![],'where':{'id':_0x1299d1[_0x13d9f7(0x14e)]['id']}};const _0x18722a={};return _0x18722a[_0x13d9f7(0x163)]=_[_0x13d9f7(0x159)](db['Trunk']['rawAttributes']),_0x18722a[_0x13d9f7(0x1a1)]=_[_0x13d9f7(0x159)](_0x1299d1['query']),_0x18722a[_0x13d9f7(0x15b)]=_[_0x13d9f7(0x183)](_0x18722a[_0x13d9f7(0x163)],_0x18722a['query']),_0x1743fe[_0x13d9f7(0x179)]=_[_0x13d9f7(0x183)](_0x18722a[_0x13d9f7(0x163)],qs[_0x13d9f7(0x180)](_0x1299d1[_0x13d9f7(0x1a1)][_0x13d9f7(0x180)])),_0x1743fe[_0x13d9f7(0x179)]=_0x1743fe[_0x13d9f7(0x179)][_0x13d9f7(0x16e)]?_0x1743fe[_0x13d9f7(0x179)]:_0x18722a[_0x13d9f7(0x163)],_0x1299d1[_0x13d9f7(0x1a1)][_0x13d9f7(0x153)]&&(_0x1743fe['include']=[{'all':!![]}]),_0x1743fe=_[_0x13d9f7(0x168)]({},_0x1743fe,_0x1299d1[_0x13d9f7(0x184)]),db[_0x13d9f7(0x16c)][_0x13d9f7(0x1a3)](_0x1743fe)['then'](handleEntityNotFound(_0x469768,null))[_0x13d9f7(0x19c)](respondWithResult(_0x469768,null))[_0x13d9f7(0x173)](handleError(_0x469768,null));},exports['clone']=function(_0x281807,_0x3f4750){const _0x18ff7f=a769_0x1ea04a;let _0x313ebc={'where':{'id':_0x281807[_0x18ff7f(0x14e)]['id']}};const _0x1a77d8={};return _0x1a77d8[_0x18ff7f(0x163)]=_[_0x18ff7f(0x159)](db[_0x18ff7f(0x16c)][_0x18ff7f(0x18d)]),_0x313ebc[_0x18ff7f(0x179)]=_[_0x18ff7f(0x183)](_0x1a77d8[_0x18ff7f(0x163)],qs['fields'](_0x281807[_0x18ff7f(0x1a1)][_0x18ff7f(0x180)])),_0x313ebc[_0x18ff7f(0x179)]=_0x313ebc[_0x18ff7f(0x179)][_0x18ff7f(0x16e)]?_0x313ebc['attributes']:_0x1a77d8[_0x18ff7f(0x163)],_0x281807[_0x18ff7f(0x1a1)]['includeAll']&&(_0x313ebc[_0x18ff7f(0x177)]=[{'all':!![]}]),_0x313ebc=_[_0x18ff7f(0x168)]({},_0x313ebc,_0x281807[_0x18ff7f(0x184)]),db[_0x18ff7f(0x16c)][_0x18ff7f(0x1a3)](_0x313ebc)[_0x18ff7f(0x19c)](handleEntityNotFound(_0x3f4750,null))[_0x18ff7f(0x19c)](function(_0x3136c9){const _0x5ed98b=_0x18ff7f;if(_0x3136c9){let _0x355095=_0x3136c9[_0x5ed98b(0x162)]({'plain':!![]});return _0x355095=qs[_0x5ed98b(0x19e)](_0x355095,['id',_0x5ed98b(0x190),'updatedAt']),_0x281807[_0x5ed98b(0x166)]=_['omit'](_0x281807[_0x5ed98b(0x166)],['id',_0x5ed98b(0x190),_0x5ed98b(0x198)]),db[_0x5ed98b(0x16c)]['create'](_[_0x5ed98b(0x168)](_0x355095,_0x281807['body']),{'include':_0x281807[_0x5ed98b(0x1a1)][_0x5ed98b(0x153)]?[{'all':!![]}]:undefined})[_0x5ed98b(0x19c)](function(_0x351e5d){const _0x47ac16=_0x5ed98b,_0x4627fa=_0x281807[_0x47ac16(0x16b)][_0x47ac16(0x162)]({'plain':!![]});if(!_0x4627fa)throw new Error(_0x47ac16(0x169));if(_0x4627fa[_0x47ac16(0x19a)]==='user'){const _0xb56597=_0x351e5d[_0x47ac16(0x162)]({'plain':!![]}),_0x58d2b3=_0x47ac16(0x185);return db[_0x47ac16(0x15e)][_0x47ac16(0x1a3)]({'where':{'name':_0x58d2b3,'userProfileId':_0x4627fa[_0x47ac16(0x193)]},'raw':!![]})[_0x47ac16(0x19c)](function(_0xab23fd){const _0x598c8a=_0x47ac16;return _0xab23fd&&_0xab23fd[_0x598c8a(0x172)]===0x0?db['UserProfileResource'][_0x598c8a(0x1a2)]({'name':_0xb56597[_0x598c8a(0x181)],'resourceId':_0xb56597['id'],'type':_0xab23fd['name'],'sectionId':_0xab23fd['id']},{})[_0x598c8a(0x19c)](function(){return _0x351e5d;}):_0x351e5d;})['catch'](function(_0x458fcb){const _0x15fda9=_0x47ac16;logger[_0x15fda9(0x15c)](_0x15fda9(0x1a0),_0x458fcb);throw _0x458fcb;});}return _0x351e5d;});}})[_0x18ff7f(0x19c)](respondWithResult(_0x3f4750,0xc9))[_0x18ff7f(0x173)](handleError(_0x3f4750,null));},exports[a769_0x1ea04a(0x1a2)]=function(_0x52642b,_0x55531b){const _0x1645c9=a769_0x1ea04a;let _0x468c33;return db[_0x1645c9(0x16c)][_0x1645c9(0x1a2)](_0x52642b[_0x1645c9(0x166)],{'raw':!![]})[_0x1645c9(0x19c)](function(_0x812c36){const _0x9cbe93=_0x1645c9;return _0x468c33=_0x812c36,db[_0x9cbe93(0x16c)][_0x9cbe93(0x188)]({'raw':!![]});})[_0x1645c9(0x19c)](function(_0x9d1478){const _0x3c6666=_0x1645c9,_0x534f2d=fs['readFileSync'](path[_0x3c6666(0x17b)](config[_0x3c6666(0x160)],_0x3c6666(0x191)),_0x3c6666(0x14c)),_0x3c6b92=fs['readFileSync'](path[_0x3c6666(0x17b)](config[_0x3c6666(0x160)],_0x3c6666(0x18f)),_0x3c6666(0x14c)),_0x40b6bf=ejs['render'](_0x534f2d,{'trunks':_0x9d1478||[]});fs[_0x3c6666(0x154)]('/etc/asterisk/sip_xcally_trunks.conf',_0x40b6bf);if(_0x468c33[_0x3c6666(0x1a4)]){const _0xbd8b82=ejs[_0x3c6666(0x18c)](_0x3c6b92,{'trunks':_0x9d1478||[]});fs[_0x3c6666(0x154)]('/etc/asterisk/sip_xcally_registers.conf',_0xbd8b82);}})[_0x1645c9(0x19c)](function(){const _0x31a885=_0x1645c9;return respondWithRpcPromise(_0x31a885(0x16d),'create',{'module':_0x31a885(0x156)});})['then'](function(){const _0x2a778d=_0x1645c9,_0x6842f9=_0x52642b[_0x2a778d(0x16b)][_0x2a778d(0x162)]({'plain':!![]});if(!_0x6842f9)throw new Error(_0x2a778d(0x169));if(_0x6842f9[_0x2a778d(0x19a)]===_0x2a778d(0x16b)){const _0xa1a76e=_0x468c33['get']({'plain':!![]});return db[_0x2a778d(0x15e)][_0x2a778d(0x1a3)]({'where':{'name':_0x2a778d(0x185),'userProfileId':_0x6842f9['userProfileId']},'raw':!![]})[_0x2a778d(0x19c)](function(_0x8d300c){const _0x58246e=_0x2a778d;return _0x8d300c&&_0x8d300c['autoAssociation']===0x0?db[_0x58246e(0x199)][_0x58246e(0x1a2)]({'name':_0xa1a76e[_0x58246e(0x181)],'resourceId':_0xa1a76e['id'],'type':_0x8d300c['name'],'sectionId':_0x8d300c['id']},{})['then'](function(){return _0x468c33;}):_0x468c33;})[_0x2a778d(0x173)](function(_0x53a9dc){const _0x202904=_0x2a778d;logger[_0x202904(0x15c)]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x53a9dc);throw _0x53a9dc;});}return _0x468c33;})[_0x1645c9(0x19c)](respondWithResult(_0x55531b,0xc9))[_0x1645c9(0x173)](handleError(_0x55531b,null));},exports['update']=function(_0x2556b7,_0x2a5213){const _0x2e1e76=a769_0x1ea04a;let _0x12473a;return db['Trunk'][_0x2e1e76(0x1a3)]({'where':{'id':_0x2556b7[_0x2e1e76(0x14e)]['id']}})[_0x2e1e76(0x19c)](handleEntityNotFound(_0x2a5213,null))[_0x2e1e76(0x19c)](saveUpdates(_0x2556b7[_0x2e1e76(0x166)],null))[_0x2e1e76(0x19c)](function(_0x526738){if(_0x526738)return _0x12473a=_0x526738,db['Trunk']['findAll']({'raw':!![]});})['then'](function(_0x38d37d){const _0x555844=_0x2e1e76;if(_0x38d37d){const _0xccbe8b=fs[_0x555844(0x19b)](path[_0x555844(0x17b)](config[_0x555844(0x160)],'files/templates/trunk.ejs'),_0x555844(0x14c)),_0x3f3711=fs[_0x555844(0x19b)](path[_0x555844(0x17b)](config[_0x555844(0x160)],_0x555844(0x18f)),_0x555844(0x14c)),_0x595a60=ejs['render'](_0xccbe8b,{'trunks':_0x38d37d||[]});fs[_0x555844(0x154)](_0x555844(0x161),_0x595a60);const _0x36c168=ejs[_0x555844(0x18c)](_0x3f3711,{'trunks':_0x38d37d||[]});return fs['writeFileSync'](_0x555844(0x15a),_0x36c168),respondWithRpcPromise(_0x555844(0x16d),_0x555844(0x150),{'module':'chan_sip.so'});}return null;})[_0x2e1e76(0x19c)](function(_0x20b9c4){if(_0x20b9c4)return _0x12473a;})[_0x2e1e76(0x19c)](respondWithResult(_0x2a5213,null))['catch'](handleError(_0x2a5213,null));},exports[a769_0x1ea04a(0x16f)]=function(_0x499dba,_0x2fde1d){const _0x37a5e1=a769_0x1ea04a;return db[_0x37a5e1(0x16c)][_0x37a5e1(0x1a3)]({'where':{'id':_0x499dba[_0x37a5e1(0x14e)]['id']}})[_0x37a5e1(0x19c)](handleEntityNotFound(_0x2fde1d,null))[_0x37a5e1(0x19c)](removeEntity(_0x2fde1d,null))[_0x37a5e1(0x19c)](function(){const _0x27f71c=_0x37a5e1;return db['Trunk'][_0x27f71c(0x188)]({'raw':!![]});})[_0x37a5e1(0x19c)](function(_0x390dee){const _0x41bbd7=_0x37a5e1,_0x1b0040=fs[_0x41bbd7(0x19b)](path['join'](config['root'],_0x41bbd7(0x191)),_0x41bbd7(0x14c)),_0x202435=fs[_0x41bbd7(0x19b)](path['join'](config['root'],_0x41bbd7(0x18f)),_0x41bbd7(0x14c)),_0x2ca6cc=ejs[_0x41bbd7(0x18c)](_0x1b0040,{'trunks':_0x390dee}),_0x4b5eab=ejs['render'](_0x202435,{'trunks':_0x390dee});return fs[_0x41bbd7(0x154)](_0x41bbd7(0x161),_0x2ca6cc),fs['writeFileSync'](_0x41bbd7(0x15a),_0x4b5eab),respondWithRpcPromise('Reload',_0x41bbd7(0x16f),{'module':_0x41bbd7(0x156)});})[_0x37a5e1(0x173)](handleError(_0x2fde1d,null));};
\ No newline at end of file