fc9ca165ca90df4d0355012c64606d19f8e059ac
[motion-next.git] / server / api / voiceContext / voiceContext.controller.js
1 const a718_0x33d2=['request\x20sent','name','sort','lodash','count','body','fieldName','Reload','readFileSync','params','render','ejs','options','get','../../mysqldb','show','Contexts','intersection','json','includeAll','writeFileSync','VoiceContext,\x20%s,\x20%s','where','order','findOne','http','jayson/promise','debug','message','then','code','key','update','../../config/logger','rows','../../components/parsers/qs','VoiceContext','utf8','destroy','fields','UserProfileResource','server/files/templates/context.ejs','attributes','VIRTUAL','userProfileId','create','stringify','error','rawAttributes','merge','map','Unable\x20to\x20retrieve\x20the\x20current\x20user','chan_sip.so','length','/etc/asterisk/extensions_xcally_contexts.conf','autoAssociation','result','info','nolimit','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','join','Content-Range','filters','limit','findAll','model','sequelize','request','status','UserProfileSection','pick','sendStatus','type','keys','set','catch','client','offset','stack','end','root','query'];(function(_0x1000dd,_0x33d277){const _0x11b228=function(_0x118feb){while(--_0x118feb){_0x1000dd['push'](_0x1000dd['shift']());}};_0x11b228(++_0x33d277);}(a718_0x33d2,0xbe));const a718_0x11b2=function(_0x1000dd,_0x33d277){_0x1000dd=_0x1000dd-0x0;let _0x11b228=a718_0x33d2[_0x1000dd];return _0x11b228;};const _0x3a0b34=a718_0x11b2;'use strict';const path=require('path'),ejs=require(_0x3a0b34('0x43')),fs=require('fs'),_=require(_0x3a0b34('0x3b')),qs=require(_0x3a0b34('0x9')),logger=require(_0x3a0b34('0x7'))('api'),config=require('../../config/environment'),db=require(_0x3a0b34('0x46'))['db'],{Op}=require(_0x3a0b34('0x28')),jayson=require(_0x3a0b34('0x0')),client=jayson[_0x3a0b34('0x32')][_0x3a0b34('0x51')]({'port':0x232a});function respondWithRpcPromise(_0x118feb,_0x1ee448,_0x22f158,_0x37800a){return new Promise(function(_0x139dcb,_0x56b614){const _0x37faeb=a718_0x11b2,_0x3690af=_0x37800a||client;return _0x3690af[_0x37faeb('0x29')](_0x118feb,_0x22f158)[_0x37faeb('0x3')](function(_0x2b9c8b){const _0x1a95ac=_0x37faeb;logger[_0x1a95ac('0x1f')](_0x1a95ac('0x4d'),_0x1ee448,_0x1a95ac('0x38')),logger[_0x1a95ac('0x1')]('VoiceContext,\x20%s,\x20%s,\x20%s',_0x1ee448,_0x1a95ac('0x38'),JSON[_0x1a95ac('0x14')](_0x2b9c8b));if(_0x2b9c8b[_0x1a95ac('0x15')]){if(_0x2b9c8b['error'][_0x1a95ac('0x4')]===0x1f4)return logger[_0x1a95ac('0x15')]('VoiceContext,\x20%s,\x20%s',_0x1ee448,_0x2b9c8b[_0x1a95ac('0x15')]['message']),_0x56b614(_0x2b9c8b[_0x1a95ac('0x15')][_0x1a95ac('0x2')]);return logger['error'](_0x1a95ac('0x4d'),_0x1ee448,_0x2b9c8b[_0x1a95ac('0x15')][_0x1a95ac('0x2')]),_0x139dcb(_0x2b9c8b['error'][_0x1a95ac('0x2')]);}else logger[_0x1a95ac('0x1f')](_0x1a95ac('0x4d'),_0x1ee448,_0x1a95ac('0x38')),_0x139dcb(_0x2b9c8b[_0x1a95ac('0x1e')]['message']);})[_0x37faeb('0x31')](function(_0x2fc2c9){const _0x311a16=_0x37faeb;logger[_0x311a16('0x15')](_0x311a16('0x4d'),_0x1ee448,_0x2fc2c9),_0x56b614(_0x2fc2c9);});});}function respondWithResult(_0x2f1b8c,_0x23c32d){return _0x23c32d=_0x23c32d||0xc8,function(_0x5513eb){const _0x48ca2d=a718_0x11b2;if(_0x5513eb)return _0x2f1b8c[_0x48ca2d('0x2a')](_0x23c32d)[_0x48ca2d('0x4a')](_0x5513eb);};}function respondWithFilteredResult(_0x48d850,_0xb93ecd){return function(_0xd363e0){const _0x20c075=a718_0x11b2;if(_0xd363e0){const _0x478f2a=_0xd363e0[_0x20c075('0x3c')],_0x326380=_0xb93ecd[_0x20c075('0x33')];let _0x1d2e56=_0xb93ecd[_0x20c075('0x33')]+_0xb93ecd[_0x20c075('0x25')],_0x2fcda9;return _0x1d2e56>=_0x478f2a?(_0x1d2e56=_0x478f2a,_0x2fcda9=0xc8):_0x2fcda9=0xce,_0x48d850['status'](_0x2fcda9),_0x48d850[_0x20c075('0x30')](_0x20c075('0x23'),_0x326380+'-'+_0x1d2e56+'/'+_0x478f2a)[_0x20c075('0x4a')](_0xd363e0);}return null;};}function saveUpdates(_0x1bfd25){return function(_0x552b24){const _0x5734a8=a718_0x11b2;if(_0x552b24)return _0x552b24['update'](_0x1bfd25)[_0x5734a8('0x3')](function(_0x5ab9cb){return _0x5ab9cb;});return null;};}function removeEntity(_0x5cb781){return function(_0x2136ed){const _0x3aa50c=a718_0x11b2;if(_0x2136ed)return _0x2136ed[_0x3aa50c('0xc')]()[_0x3aa50c('0x3')](function(){const _0x4b4502=_0x3aa50c,_0x12549f=_0x2136ed[_0x4b4502('0x45')]({'plain':!![]}),_0x43bb09=_0x4b4502('0x48');return db[_0x4b4502('0xe')][_0x4b4502('0xc')]({'where':{'type':_0x43bb09,'resourceId':_0x12549f['id']}})[_0x4b4502('0x3')](function(){return _0x2136ed;});})[_0x3aa50c('0x3')](function(){const _0x10c22f=_0x3aa50c;_0x5cb781[_0x10c22f('0x2a')](0xcc)[_0x10c22f('0x35')]();});};}function handleEntityNotFound(_0x271f98){return function(_0x9f212){const _0x4ca50a=a718_0x11b2;return!_0x9f212&&_0x271f98[_0x4ca50a('0x2d')](0x194),_0x9f212;};}function handleError(_0x1cec62,_0x1789cd){return _0x1789cd=_0x1789cd||0x1f4,function(_0x2aa629){const _0x7de84a=a718_0x11b2;logger[_0x7de84a('0x15')](_0x2aa629[_0x7de84a('0x34')]),_0x2aa629[_0x7de84a('0x39')]&&delete _0x2aa629[_0x7de84a('0x39')],_0x1cec62[_0x7de84a('0x2a')](_0x1789cd)['send'](_0x2aa629);};}exports['index']=function(_0x15c950,_0x1e5479){const _0x395563=_0x3a0b34;let _0x5a2c66={};const _0x36e959={},_0x2ed21c={'count':0x0,'rows':[]},_0x336052=_[_0x395563('0x18')](db[_0x395563('0xa')][_0x395563('0x16')],function(_0x2e6539){const _0x3600e1=_0x395563;return{'name':_0x2e6539[_0x3600e1('0x3e')],'type':_0x2e6539[_0x3600e1('0x2e')][_0x3600e1('0x5')]};});_0x36e959[_0x395563('0x27')]=_[_0x395563('0x18')](_0x336052,_0x395563('0x39')),_0x36e959['query']=_[_0x395563('0x2f')](_0x15c950[_0x395563('0x37')]),_0x36e959['filters']=_[_0x395563('0x49')](_0x36e959[_0x395563('0x27')],_0x36e959[_0x395563('0x37')]),_0x5a2c66[_0x395563('0x10')]=_['intersection'](_0x36e959[_0x395563('0x27')],qs[_0x395563('0xd')](_0x15c950[_0x395563('0x37')][_0x395563('0xd')])),_0x5a2c66[_0x395563('0x10')]=_0x5a2c66[_0x395563('0x10')][_0x395563('0x1b')]?_0x5a2c66[_0x395563('0x10')]:_0x36e959['model'];typeof _0x15c950[_0x395563('0x37')][_0x395563('0x20')]==='undefined'&&(_0x5a2c66['limit']=qs['limit'](_0x15c950[_0x395563('0x37')][_0x395563('0x25')]),_0x5a2c66['offset']=qs[_0x395563('0x33')](_0x15c950[_0x395563('0x37')][_0x395563('0x33')]));_0x5a2c66[_0x395563('0x4f')]=qs[_0x395563('0x3a')](_0x15c950[_0x395563('0x37')][_0x395563('0x3a')]),_0x5a2c66[_0x395563('0x4e')]=qs[_0x395563('0x24')](_[_0x395563('0x2c')](_0x15c950['query'],_0x36e959[_0x395563('0x24')]),_0x336052);_0x15c950[_0x395563('0x37')]['filter']&&(_0x5a2c66[_0x395563('0x4e')]=_[_0x395563('0x17')](_0x5a2c66[_0x395563('0x4e')],{[Op['or']]:_[_0x395563('0x18')](_0x336052,function(_0x8ff331){const _0x204bcb=_0x395563;if(_0x8ff331[_0x204bcb('0x2e')]!==_0x204bcb('0x11')){const _0x2a53f4={};return _0x2a53f4[_0x8ff331[_0x204bcb('0x39')]]={[Op['like']]:'%'+_0x15c950[_0x204bcb('0x37')]['filter']+'%'},_0x2a53f4;}})}));_0x5a2c66=_[_0x395563('0x17')]({},_0x5a2c66,_0x15c950[_0x395563('0x44')]);const _0x43bdc0={'where':_0x5a2c66[_0x395563('0x4e')]};return db[_0x395563('0xa')][_0x395563('0x3c')](_0x43bdc0)[_0x395563('0x3')](function(_0x2abfd4){const _0x33cbff=_0x395563;return _0x2ed21c[_0x33cbff('0x3c')]=_0x2abfd4,_0x15c950[_0x33cbff('0x37')][_0x33cbff('0x4b')]&&(_0x5a2c66['include']=[{'all':!![]}]),db['VoiceContext'][_0x33cbff('0x26')](_0x5a2c66);})[_0x395563('0x3')](function(_0x112691){const _0x77836f=_0x395563;return _0x2ed21c[_0x77836f('0x8')]=_0x112691,_0x2ed21c;})[_0x395563('0x3')](respondWithFilteredResult(_0x1e5479,_0x5a2c66))[_0x395563('0x31')](handleError(_0x1e5479,null));},exports[_0x3a0b34('0x47')]=function(_0x317467,_0x33318f){const _0x29199f=_0x3a0b34;let _0x523410={'raw':![],'where':{'id':_0x317467['params']['id']}};const _0x46031e={};return _0x46031e['model']=_[_0x29199f('0x2f')](db[_0x29199f('0xa')][_0x29199f('0x16')]),_0x46031e[_0x29199f('0x37')]=_[_0x29199f('0x2f')](_0x317467[_0x29199f('0x37')]),_0x46031e[_0x29199f('0x24')]=_[_0x29199f('0x49')](_0x46031e[_0x29199f('0x27')],_0x46031e['query']),_0x523410[_0x29199f('0x10')]=_['intersection'](_0x46031e[_0x29199f('0x27')],qs['fields'](_0x317467[_0x29199f('0x37')][_0x29199f('0xd')])),_0x523410[_0x29199f('0x10')]=_0x523410[_0x29199f('0x10')][_0x29199f('0x1b')]?_0x523410['attributes']:_0x46031e[_0x29199f('0x27')],_0x317467[_0x29199f('0x37')]['includeAll']&&(_0x523410['include']=[{'all':!![]}]),_0x523410=_[_0x29199f('0x17')]({},_0x523410,_0x317467['options']),db[_0x29199f('0xa')][_0x29199f('0x50')](_0x523410)[_0x29199f('0x3')](handleEntityNotFound(_0x33318f,null))[_0x29199f('0x3')](respondWithResult(_0x33318f,null))[_0x29199f('0x31')](handleError(_0x33318f,null));},exports['create']=function(_0x8c2720,_0x542a45){const _0x2d2bfb=_0x3a0b34;let _0x81f87c;return db[_0x2d2bfb('0xa')][_0x2d2bfb('0x13')](_0x8c2720['body'],{'raw':!![]})[_0x2d2bfb('0x3')](function(_0x3b7c41){const _0x12621f=_0x2d2bfb;return _0x81f87c=_0x3b7c41,db[_0x12621f('0xa')][_0x12621f('0x26')]({'raw':!![]});})[_0x2d2bfb('0x3')](function(_0x279812){const _0x578612=_0x2d2bfb,_0x703fdf=fs[_0x578612('0x40')](path[_0x578612('0x22')](config[_0x578612('0x36')],_0x578612('0xf')),_0x578612('0xb')),_0x175232=ejs['render'](_0x703fdf,{'contexts':_0x279812||[]});fs[_0x578612('0x4c')]('/etc/asterisk/extensions_xcally_contexts.conf',_0x175232);})[_0x2d2bfb('0x3')](function(){return respondWithRpcPromise('Reload','create',{'module':'chan_sip.so'});})[_0x2d2bfb('0x3')](function(){const _0x346d96=_0x2d2bfb,_0x594dd6=_0x8c2720['user'][_0x346d96('0x45')]({'plain':!![]});if(!_0x594dd6)throw new Error(_0x346d96('0x19'));if(_0x594dd6['role']==='user'){const _0x2a0baf=_0x81f87c['get']({'plain':!![]});return db[_0x346d96('0x2b')][_0x346d96('0x50')]({'where':{'name':_0x346d96('0x48'),'userProfileId':_0x594dd6[_0x346d96('0x12')]},'raw':!![]})[_0x346d96('0x3')](function(_0x3069b5){const _0x527d09=_0x346d96;return _0x3069b5&&_0x3069b5[_0x527d09('0x1d')]===0x0?db[_0x527d09('0xe')][_0x527d09('0x13')]({'name':_0x2a0baf[_0x527d09('0x39')],'resourceId':_0x2a0baf['id'],'type':_0x3069b5[_0x527d09('0x39')],'sectionId':_0x3069b5['id']},{})[_0x527d09('0x3')](function(){return _0x81f87c;}):_0x81f87c;})[_0x346d96('0x31')](function(_0x1e055f){const _0x56c644=_0x346d96;logger[_0x56c644('0x15')](_0x56c644('0x21'),_0x1e055f);throw _0x1e055f;});}return _0x81f87c;})['then'](respondWithResult(_0x542a45,0xc9))[_0x2d2bfb('0x31')](handleError(_0x542a45,null));},exports[_0x3a0b34('0x6')]=function(_0x48c28d,_0x1c881d){const _0x132db3=_0x3a0b34;let _0x198344;return db[_0x132db3('0xa')][_0x132db3('0x50')]({'where':{'id':_0x48c28d[_0x132db3('0x41')]['id']}})[_0x132db3('0x3')](handleEntityNotFound(_0x1c881d,null))[_0x132db3('0x3')](saveUpdates(_0x48c28d[_0x132db3('0x3d')],null))[_0x132db3('0x3')](function(_0x11c05d){const _0x5ec7c5=_0x132db3;if(_0x11c05d)return _0x198344=_0x11c05d,db[_0x5ec7c5('0xa')][_0x5ec7c5('0x26')]({'raw':!![]});})['then'](function(_0x3e99ad){const _0x3ae095=_0x132db3,_0x5ed12d=fs[_0x3ae095('0x40')](path['join'](config['root'],'server/files/templates/context.ejs'),_0x3ae095('0xb')),_0x4d31ac=ejs['render'](_0x5ed12d,{'contexts':_0x3e99ad||[]});fs['writeFileSync'](_0x3ae095('0x1c'),_0x4d31ac);})[_0x132db3('0x3')](function(){const _0xe42e31=_0x132db3;return respondWithRpcPromise(_0xe42e31('0x3f'),_0xe42e31('0x6'),{'module':_0xe42e31('0x1a')});})[_0x132db3('0x3')](function(){return _0x198344;})[_0x132db3('0x3')](respondWithResult(_0x1c881d,null))[_0x132db3('0x31')](handleError(_0x1c881d,null));},exports[_0x3a0b34('0xc')]=function(_0x225961,_0x27f7c2){const _0x188150=_0x3a0b34;return db[_0x188150('0xa')]['findOne']({'where':{'id':_0x225961[_0x188150('0x41')]['id']}})[_0x188150('0x3')](handleEntityNotFound(_0x27f7c2,null))[_0x188150('0x3')](removeEntity(_0x27f7c2,null))[_0x188150('0x3')](function(){const _0x15fd02=_0x188150;return db[_0x15fd02('0xa')][_0x15fd02('0x26')]({'raw':!![]});})['then'](function(_0x3183ba){const _0x3cbaa7=_0x188150,_0x56ca20=fs[_0x3cbaa7('0x40')](path['join'](config[_0x3cbaa7('0x36')],_0x3cbaa7('0xf')),_0x3cbaa7('0xb')),_0x21fe40=ejs[_0x3cbaa7('0x42')](_0x56ca20,{'contexts':_0x3183ba});return fs[_0x3cbaa7('0x4c')]('/etc/asterisk/extensions_xcally_contexts.conf',_0x21fe40),respondWithRpcPromise('Reload',_0x3cbaa7('0xc'),{'module':_0x3cbaa7('0x1a')});})[_0x188150('0x31')](handleError(_0x27f7c2,null));};