Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / voiceContext / voiceContext.controller.js
index 8e8df83..0ba9dba 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfa35=['debug','VoiceContext,\x20%s,\x20%s,\x20%s','stringify','error','VoiceContext,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','get','stack','name','send','index','rawAttributes','fieldName','key','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filters','filter','where','merge','map','type','options','VoiceContext','includeAll','rows','show','params','include','find','create','body','findAll','readFileSync','join','root','server/files/templates/context.ejs','utf8','render','writeFileSync','/etc/asterisk/extensions_xcally_contexts.conf','Reload','chan_sip.so','user','UserProfileSection','Contexts','userProfileId','autoAssociation','UserProfileResource','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','ejs','fs-extra','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/license/util','jayson/promise','client','http','request','request\x20sent'];(function(_0xda923,_0x50b57b){var _0x3b2afb=function(_0x469da1){while(--_0x469da1){_0xda923['push'](_0xda923['shift']());}};_0x3b2afb(++_0x50b57b);}(_0xfa35,0x188));var _0x5fa3=function(_0xa38daf,_0x30406b){_0xa38daf=_0xa38daf-0x0;var _0x1b786a=_0xfa35[_0xa38daf];return _0x1b786a;};'use strict';var emlformat=require(_0x5fa3('0x0'));var rimraf=require(_0x5fa3('0x1'));var zipdir=require(_0x5fa3('0x2'));var jsonpatch=require(_0x5fa3('0x3'));var rp=require(_0x5fa3('0x4'));var moment=require('moment');var BPromise=require(_0x5fa3('0x5'));var Mustache=require(_0x5fa3('0x6'));var util=require(_0x5fa3('0x7'));var path=require('path');var sox=require(_0x5fa3('0x8'));var csv=require('to-csv');var ejs=require(_0x5fa3('0x9'));var fs=require('fs');var fs_extra=require(_0x5fa3('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x5fa3('0xb'));var jsforce=require(_0x5fa3('0xc'));var deskjs=require(_0x5fa3('0xd'));var toCsv=require(_0x5fa3('0xe'));var querystring=require('querystring');var Papa=require(_0x5fa3('0xf'));var Redis=require(_0x5fa3('0x10'));var authService=require(_0x5fa3('0x11'));var qs=require(_0x5fa3('0x12'));var as=require(_0x5fa3('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x5fa3('0x14'))('api');var utils=require(_0x5fa3('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x5fa3('0x16'));var db=require('../../mysqldb')['db'];var jayson=require(_0x5fa3('0x17'));var client=jayson[_0x5fa3('0x18')][_0x5fa3('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x34f7d4,_0x744fb6,_0x1abadc,_0x3fa422){return new BPromise(function(_0x37722f,_0x461dfd){var _0x24e920=_0x3fa422||client;return _0x24e920[_0x5fa3('0x1a')](_0x34f7d4,_0x1abadc)['then'](function(_0x2bb347){logger['info']('VoiceContext,\x20%s,\x20%s',_0x744fb6,_0x5fa3('0x1b'));logger[_0x5fa3('0x1c')](_0x5fa3('0x1d'),_0x744fb6,_0x5fa3('0x1b'),JSON[_0x5fa3('0x1e')](_0x2bb347));if(_0x2bb347[_0x5fa3('0x1f')]){if(_0x2bb347['error']['code']===0x1f4){logger[_0x5fa3('0x1f')](_0x5fa3('0x20'),_0x744fb6,_0x2bb347[_0x5fa3('0x1f')][_0x5fa3('0x21')]);return _0x461dfd(_0x2bb347['error'][_0x5fa3('0x21')]);}logger[_0x5fa3('0x1f')](_0x5fa3('0x20'),_0x744fb6,_0x2bb347[_0x5fa3('0x1f')][_0x5fa3('0x21')]);return _0x37722f(_0x2bb347[_0x5fa3('0x1f')][_0x5fa3('0x21')]);}else{logger['info'](_0x5fa3('0x20'),_0x744fb6,'request\x20sent');_0x37722f(_0x2bb347[_0x5fa3('0x22')][_0x5fa3('0x21')]);}})[_0x5fa3('0x23')](function(_0x4ad942){logger[_0x5fa3('0x1f')]('VoiceContext,\x20%s,\x20%s',_0x744fb6,_0x4ad942);_0x461dfd(_0x4ad942);});});}function respondWithStatusCode(_0x4e1bdf,_0x342af5){_0x342af5=_0x342af5||0xcc;return function(_0x3f4a11){if(_0x3f4a11){return _0x4e1bdf[_0x5fa3('0x24')](_0x342af5);}return _0x4e1bdf[_0x5fa3('0x25')](_0x342af5)[_0x5fa3('0x26')]();};}function respondWithResult(_0x3ec7a8,_0x2978c7){_0x2978c7=_0x2978c7||0xc8;return function(_0x12eeb1){if(_0x12eeb1){return _0x3ec7a8['status'](_0x2978c7)[_0x5fa3('0x27')](_0x12eeb1);}};}function respondWithFilteredResult(_0x5b963d,_0x56796f){return function(_0xab9efa){if(_0xab9efa){var _0x5dd1df=typeof _0x56796f['offset']===_0x5fa3('0x28')&&typeof _0x56796f[_0x5fa3('0x29')]===_0x5fa3('0x28');var _0x514892=_0xab9efa[_0x5fa3('0x2a')];var _0x3c4c61=_0x5dd1df?0x0:_0x56796f[_0x5fa3('0x2b')];var _0x1664b8=_0x5dd1df?_0xab9efa[_0x5fa3('0x2a')]:_0x56796f[_0x5fa3('0x2b')]+_0x56796f[_0x5fa3('0x29')];var _0x75321c;if(_0x1664b8>=_0x514892){_0x1664b8=_0x514892;_0x75321c=0xc8;}else{_0x75321c=0xce;}_0x5b963d[_0x5fa3('0x25')](_0x75321c);return _0x5b963d[_0x5fa3('0x2c')](_0x5fa3('0x2d'),_0x3c4c61+'-'+_0x1664b8+'/'+_0x514892)[_0x5fa3('0x27')](_0xab9efa);}return null;};}function patchUpdates(_0x39e8d3){return function(_0x40e3fe){try{jsonpatch[_0x5fa3('0x2e')](_0x40e3fe,_0x39e8d3,!![]);}catch(_0x5e935b){return BPromise[_0x5fa3('0x2f')](_0x5e935b);}return _0x40e3fe[_0x5fa3('0x30')]();};}function saveUpdates(_0x3e35e7,_0x4cbc65){return function(_0x9ccc6b){if(_0x9ccc6b){return _0x9ccc6b[_0x5fa3('0x31')](_0x3e35e7)[_0x5fa3('0x32')](function(_0x4d0b23){return _0x4d0b23;});}return null;};}function removeEntity(_0x2463f2,_0x595922){return function(_0x420336){if(_0x420336){return _0x420336[_0x5fa3('0x33')]()[_0x5fa3('0x32')](function(){var _0x25db71=_0x420336[_0x5fa3('0x34')]({'plain':!![]});var _0x34af4c='Contexts';return db['UserProfileResource'][_0x5fa3('0x33')]({'where':{'type':_0x34af4c,'resourceId':_0x25db71['id']}})[_0x5fa3('0x32')](function(){return _0x420336;});})[_0x5fa3('0x32')](function(){_0x2463f2['status'](0xcc)[_0x5fa3('0x26')]();});}};}function handleEntityNotFound(_0x38bbd2,_0x3df959){return function(_0x3f2f78){if(!_0x3f2f78){_0x38bbd2[_0x5fa3('0x24')](0x194);}return _0x3f2f78;};}function handleError(_0x5b1665,_0x596f20){_0x596f20=_0x596f20||0x1f4;return function(_0x283fc9){logger['error'](_0x283fc9[_0x5fa3('0x35')]);if(_0x283fc9[_0x5fa3('0x36')]){delete _0x283fc9[_0x5fa3('0x36')];}_0x5b1665[_0x5fa3('0x25')](_0x596f20)[_0x5fa3('0x37')](_0x283fc9);};}exports[_0x5fa3('0x38')]=function(_0x538356,_0x36d1a0){var _0x17b41e={},_0x525972={},_0x4b301d={'count':0x0,'rows':[]};var _0x32c64f=_['map'](db['VoiceContext'][_0x5fa3('0x39')],function(_0x4aff9f){return{'name':_0x4aff9f[_0x5fa3('0x3a')],'type':_0x4aff9f['type'][_0x5fa3('0x3b')]};});_0x525972[_0x5fa3('0x3c')]=_['map'](_0x32c64f,'name');_0x525972[_0x5fa3('0x3d')]=_[_0x5fa3('0x3e')](_0x538356[_0x5fa3('0x3d')]);_0x525972['filters']=_['intersection'](_0x525972[_0x5fa3('0x3c')],_0x525972['query']);_0x17b41e[_0x5fa3('0x3f')]=_[_0x5fa3('0x40')](_0x525972[_0x5fa3('0x3c')],qs['fields'](_0x538356[_0x5fa3('0x3d')][_0x5fa3('0x41')]));_0x17b41e['attributes']=_0x17b41e[_0x5fa3('0x3f')][_0x5fa3('0x42')]?_0x17b41e[_0x5fa3('0x3f')]:_0x525972['model'];if(!_0x538356[_0x5fa3('0x3d')][_0x5fa3('0x43')](_0x5fa3('0x44'))){_0x17b41e[_0x5fa3('0x29')]=qs[_0x5fa3('0x29')](_0x538356['query'][_0x5fa3('0x29')]);_0x17b41e['offset']=qs[_0x5fa3('0x2b')](_0x538356[_0x5fa3('0x3d')][_0x5fa3('0x2b')]);}_0x17b41e[_0x5fa3('0x45')]=qs[_0x5fa3('0x46')](_0x538356[_0x5fa3('0x3d')][_0x5fa3('0x46')]);_0x17b41e['where']=qs['filters'](_[_0x5fa3('0x47')](_0x538356['query'],_0x525972[_0x5fa3('0x48')]),_0x32c64f);if(_0x538356[_0x5fa3('0x3d')][_0x5fa3('0x49')]){_0x17b41e[_0x5fa3('0x4a')]=_[_0x5fa3('0x4b')](_0x17b41e['where'],{'$or':_[_0x5fa3('0x4c')](_0x32c64f,function(_0x573e28){if(_0x573e28[_0x5fa3('0x4d')]!=='VIRTUAL'){var _0x2cfb3c={};_0x2cfb3c[_0x573e28[_0x5fa3('0x36')]]={'$like':'%'+_0x538356[_0x5fa3('0x3d')][_0x5fa3('0x49')]+'%'};return _0x2cfb3c;}})});}_0x17b41e=_['merge']({},_0x17b41e,_0x538356[_0x5fa3('0x4e')]);var _0x179ca5={'where':_0x17b41e[_0x5fa3('0x4a')]};return db[_0x5fa3('0x4f')]['count'](_0x179ca5)[_0x5fa3('0x32')](function(_0xd79524){_0x4b301d['count']=_0xd79524;if(_0x538356['query'][_0x5fa3('0x50')]){_0x17b41e['include']=[{'all':!![]}];}return db[_0x5fa3('0x4f')]['findAll'](_0x17b41e);})[_0x5fa3('0x32')](function(_0x2dea41){_0x4b301d[_0x5fa3('0x51')]=_0x2dea41;return _0x4b301d;})[_0x5fa3('0x32')](respondWithFilteredResult(_0x36d1a0,_0x17b41e))[_0x5fa3('0x23')](handleError(_0x36d1a0,null));};exports[_0x5fa3('0x52')]=function(_0x4b9b8d,_0x19052e){var _0x3c58ac={'raw':![],'where':{'id':_0x4b9b8d[_0x5fa3('0x53')]['id']}},_0x3b0ce1={};_0x3b0ce1[_0x5fa3('0x3c')]=_['keys'](db[_0x5fa3('0x4f')][_0x5fa3('0x39')]);_0x3b0ce1['query']=_[_0x5fa3('0x3e')](_0x4b9b8d[_0x5fa3('0x3d')]);_0x3b0ce1[_0x5fa3('0x48')]=_[_0x5fa3('0x40')](_0x3b0ce1[_0x5fa3('0x3c')],_0x3b0ce1['query']);_0x3c58ac[_0x5fa3('0x3f')]=_['intersection'](_0x3b0ce1[_0x5fa3('0x3c')],qs['fields'](_0x4b9b8d[_0x5fa3('0x3d')][_0x5fa3('0x41')]));_0x3c58ac[_0x5fa3('0x3f')]=_0x3c58ac[_0x5fa3('0x3f')][_0x5fa3('0x42')]?_0x3c58ac[_0x5fa3('0x3f')]:_0x3b0ce1[_0x5fa3('0x3c')];if(_0x4b9b8d[_0x5fa3('0x3d')][_0x5fa3('0x50')]){_0x3c58ac[_0x5fa3('0x54')]=[{'all':!![]}];}_0x3c58ac=_[_0x5fa3('0x4b')]({},_0x3c58ac,_0x4b9b8d[_0x5fa3('0x4e')]);return db[_0x5fa3('0x4f')][_0x5fa3('0x55')](_0x3c58ac)[_0x5fa3('0x32')](handleEntityNotFound(_0x19052e,null))[_0x5fa3('0x32')](respondWithResult(_0x19052e,null))[_0x5fa3('0x23')](handleError(_0x19052e,null));};exports[_0x5fa3('0x56')]=function(_0x336161,_0x5f1fea,_0x2e6c7f){var _0x4a3593;return db[_0x5fa3('0x4f')][_0x5fa3('0x56')](_0x336161[_0x5fa3('0x57')],{'raw':!![]})[_0x5fa3('0x32')](function(_0x240aff){_0x4a3593=_0x240aff;return db[_0x5fa3('0x4f')][_0x5fa3('0x58')]({'raw':!![]});})['then'](function(_0x523eef){var _0x1767d1=fs[_0x5fa3('0x59')](path[_0x5fa3('0x5a')](config[_0x5fa3('0x5b')],_0x5fa3('0x5c')),_0x5fa3('0x5d'));var _0xa1e58c=ejs[_0x5fa3('0x5e')](_0x1767d1,{'contexts':_0x523eef||[]});fs[_0x5fa3('0x5f')](_0x5fa3('0x60'),_0xa1e58c);})[_0x5fa3('0x32')](function(){return respondWithRpcPromise(_0x5fa3('0x61'),_0x5fa3('0x56'),{'module':_0x5fa3('0x62')});})[_0x5fa3('0x32')](function(){var _0x25d46c=_0x336161[_0x5fa3('0x63')][_0x5fa3('0x34')]({'plain':!![]});if(!_0x25d46c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x25d46c['role']===_0x5fa3('0x63')){var _0x1ca8fe=_0x4a3593[_0x5fa3('0x34')]({'plain':!![]});return db[_0x5fa3('0x64')][_0x5fa3('0x55')]({'where':{'name':_0x5fa3('0x65'),'userProfileId':_0x25d46c[_0x5fa3('0x66')]},'raw':!![]})['then'](function(_0xa1a49a){if(_0xa1a49a&&_0xa1a49a[_0x5fa3('0x67')]===0x0){return db[_0x5fa3('0x68')]['create']({'name':_0x1ca8fe[_0x5fa3('0x36')],'resourceId':_0x1ca8fe['id'],'type':_0xa1a49a[_0x5fa3('0x36')],'sectionId':_0xa1a49a['id']},{})[_0x5fa3('0x32')](function(){return _0x4a3593;});}else{return _0x4a3593;}})[_0x5fa3('0x23')](function(_0x25e887){logger[_0x5fa3('0x1f')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x25e887);throw _0x25e887;});}return _0x4a3593;})['then'](respondWithResult(_0x5f1fea,0xc9))[_0x5fa3('0x23')](handleError(_0x5f1fea,null));};exports[_0x5fa3('0x31')]=function(_0x43e733,_0x1139c8,_0x3a9ec3){var _0x533766;return db[_0x5fa3('0x4f')][_0x5fa3('0x55')]({'where':{'id':_0x43e733['params']['id']}})['then'](handleEntityNotFound(_0x1139c8,null))[_0x5fa3('0x32')](saveUpdates(_0x43e733['body'],null))[_0x5fa3('0x32')](function(_0x43e2cc){if(_0x43e2cc){_0x533766=_0x43e2cc;return db[_0x5fa3('0x4f')][_0x5fa3('0x58')]({'raw':!![]});}})[_0x5fa3('0x32')](function(_0x4ac1bb){var _0xea4d4=fs[_0x5fa3('0x59')](path['join'](config['root'],_0x5fa3('0x5c')),_0x5fa3('0x5d'));var _0x3d4443=ejs['render'](_0xea4d4,{'contexts':_0x4ac1bb||[]});fs['writeFileSync'](_0x5fa3('0x60'),_0x3d4443);})['then'](function(){return respondWithRpcPromise(_0x5fa3('0x61'),'update',{'module':_0x5fa3('0x62')});})[_0x5fa3('0x32')](function(){return _0x533766;})[_0x5fa3('0x32')](respondWithResult(_0x1139c8,null))[_0x5fa3('0x23')](handleError(_0x1139c8,null));};exports[_0x5fa3('0x33')]=function(_0x35fa42,_0x10367c,_0x1db273){var _0x3536fe;return db[_0x5fa3('0x4f')][_0x5fa3('0x55')]({'where':{'id':_0x35fa42[_0x5fa3('0x53')]['id']}})[_0x5fa3('0x32')](handleEntityNotFound(_0x10367c,null))['then'](removeEntity(_0x10367c,null))[_0x5fa3('0x32')](function(){return db['VoiceContext'][_0x5fa3('0x58')]({'raw':!![]});})[_0x5fa3('0x32')](function(_0x2cf090){var _0x5c92c5=fs[_0x5fa3('0x59')](path[_0x5fa3('0x5a')](config[_0x5fa3('0x5b')],_0x5fa3('0x5c')),'utf8');var _0xde628f=ejs['render'](_0x5c92c5,{'contexts':_0x2cf090});fs[_0x5fa3('0x5f')](_0x5fa3('0x60'),_0xde628f);return respondWithRpcPromise(_0x5fa3('0x61'),_0x5fa3('0x33'),{'module':_0x5fa3('0x62')});})[_0x5fa3('0x23')](handleError(_0x10367c,null));};
\ No newline at end of file
+var _0x10f6=['ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','request','then','info','VoiceContext,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','count','set','apply','reject','destroy','get','Contexts','UserProfileResource','name','index','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','map','VIRTUAL','merge','options','VoiceContext','includeAll','include','findAll','rows','show','params','intersection','find','create','body','readFileSync','join','root','server/files/templates/context.ejs','utf8','render','writeFileSync','Reload','chan_sip.so','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','/etc/asterisk/extensions_xcally_contexts.conf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse'];(function(_0x39e84d,_0x11931d){var _0x1991bc=function(_0xc81e32){while(--_0xc81e32){_0x39e84d['push'](_0x39e84d['shift']());}};_0x1991bc(++_0x11931d);}(_0x10f6,0xc7));var _0x610f=function(_0x2b9202,_0x2a8edb){_0x2b9202=_0x2b9202-0x0;var _0x85f119=_0x10f6[_0x2b9202];return _0x85f119;};'use strict';var emlformat=require(_0x610f('0x0'));var rimraf=require(_0x610f('0x1'));var zipdir=require(_0x610f('0x2'));var jsonpatch=require(_0x610f('0x3'));var rp=require(_0x610f('0x4'));var moment=require(_0x610f('0x5'));var BPromise=require(_0x610f('0x6'));var Mustache=require(_0x610f('0x7'));var util=require('util');var path=require(_0x610f('0x8'));var sox=require(_0x610f('0x9'));var csv=require(_0x610f('0xa'));var ejs=require(_0x610f('0xb'));var fs=require('fs');var fs_extra=require(_0x610f('0xc'));var _=require(_0x610f('0xd'));var squel=require(_0x610f('0xe'));var crypto=require(_0x610f('0xf'));var jsforce=require(_0x610f('0x10'));var deskjs=require('desk.js');var toCsv=require(_0x610f('0xa'));var querystring=require(_0x610f('0x11'));var Papa=require(_0x610f('0x12'));var Redis=require(_0x610f('0x13'));var authService=require(_0x610f('0x14'));var qs=require(_0x610f('0x15'));var as=require(_0x610f('0x16'));var hardwareService=require(_0x610f('0x17'));var logger=require('../../config/logger')(_0x610f('0x18'));var utils=require('../../config/utils');var config=require(_0x610f('0x19'));var licenseUtil=require(_0x610f('0x1a'));var db=require(_0x610f('0x1b'))['db'];var jayson=require(_0x610f('0x1c'));var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x14b78e,_0x432216,_0x22773b,_0x23b8dc){return new BPromise(function(_0x11ae46,_0xee6ea3){var _0x4938a2=_0x23b8dc||client;return _0x4938a2[_0x610f('0x1d')](_0x14b78e,_0x22773b)[_0x610f('0x1e')](function(_0x2748db){logger[_0x610f('0x1f')](_0x610f('0x20'),_0x432216,_0x610f('0x21'));logger[_0x610f('0x22')]('VoiceContext,\x20%s,\x20%s,\x20%s',_0x432216,_0x610f('0x21'),JSON[_0x610f('0x23')](_0x2748db));if(_0x2748db[_0x610f('0x24')]){if(_0x2748db[_0x610f('0x24')][_0x610f('0x25')]===0x1f4){logger['error'](_0x610f('0x20'),_0x432216,_0x2748db[_0x610f('0x24')]['message']);return _0xee6ea3(_0x2748db[_0x610f('0x24')][_0x610f('0x26')]);}logger[_0x610f('0x24')]('VoiceContext,\x20%s,\x20%s',_0x432216,_0x2748db[_0x610f('0x24')][_0x610f('0x26')]);return _0x11ae46(_0x2748db[_0x610f('0x24')][_0x610f('0x26')]);}else{logger[_0x610f('0x1f')](_0x610f('0x20'),_0x432216,_0x610f('0x21'));_0x11ae46(_0x2748db[_0x610f('0x27')][_0x610f('0x26')]);}})[_0x610f('0x28')](function(_0x5ed720){logger[_0x610f('0x24')](_0x610f('0x20'),_0x432216,_0x5ed720);_0xee6ea3(_0x5ed720);});});}function respondWithStatusCode(_0x412142,_0x5edf30){_0x5edf30=_0x5edf30||0xcc;return function(_0x577845){if(_0x577845){return _0x412142[_0x610f('0x29')](_0x5edf30);}return _0x412142[_0x610f('0x2a')](_0x5edf30)[_0x610f('0x2b')]();};}function respondWithResult(_0x5d0f59,_0xa5d7c0){_0xa5d7c0=_0xa5d7c0||0xc8;return function(_0x47c07e){if(_0x47c07e){return _0x5d0f59['status'](_0xa5d7c0)[_0x610f('0x2c')](_0x47c07e);}};}function respondWithFilteredResult(_0x1744bb,_0x3175ff){return function(_0x5c7d86){if(_0x5c7d86){var _0x38b348=typeof _0x3175ff[_0x610f('0x2d')]===_0x610f('0x2e')&&typeof _0x3175ff['limit']===_0x610f('0x2e');var _0x2c81de=_0x5c7d86['count'];var _0x43c83d=_0x38b348?0x0:_0x3175ff[_0x610f('0x2d')];var _0x1fd7d1=_0x38b348?_0x5c7d86[_0x610f('0x2f')]:_0x3175ff[_0x610f('0x2d')]+_0x3175ff['limit'];var _0x4a0e16;if(_0x1fd7d1>=_0x2c81de){_0x1fd7d1=_0x2c81de;_0x4a0e16=0xc8;}else{_0x4a0e16=0xce;}_0x1744bb[_0x610f('0x2a')](_0x4a0e16);return _0x1744bb[_0x610f('0x30')]('Content-Range',_0x43c83d+'-'+_0x1fd7d1+'/'+_0x2c81de)['json'](_0x5c7d86);}return null;};}function patchUpdates(_0x2c537c){return function(_0x2e2bd2){try{jsonpatch[_0x610f('0x31')](_0x2e2bd2,_0x2c537c,!![]);}catch(_0x1d2100){return BPromise[_0x610f('0x32')](_0x1d2100);}return _0x2e2bd2['save']();};}function saveUpdates(_0x556611,_0x104fce){return function(_0x1dbb34){if(_0x1dbb34){return _0x1dbb34['update'](_0x556611)[_0x610f('0x1e')](function(_0xae571e){return _0xae571e;});}return null;};}function removeEntity(_0x3837ea,_0x220325){return function(_0x304022){if(_0x304022){return _0x304022[_0x610f('0x33')]()[_0x610f('0x1e')](function(){var _0x16a57d=_0x304022[_0x610f('0x34')]({'plain':!![]});var _0x394431=_0x610f('0x35');return db[_0x610f('0x36')]['destroy']({'where':{'type':_0x394431,'resourceId':_0x16a57d['id']}})[_0x610f('0x1e')](function(){return _0x304022;});})[_0x610f('0x1e')](function(){_0x3837ea['status'](0xcc)[_0x610f('0x2b')]();});}};}function handleEntityNotFound(_0x43d878,_0x3baf9e){return function(_0x1c36a7){if(!_0x1c36a7){_0x43d878[_0x610f('0x29')](0x194);}return _0x1c36a7;};}function handleError(_0x2fc77c,_0x18a4d0){_0x18a4d0=_0x18a4d0||0x1f4;return function(_0x16e2df){logger[_0x610f('0x24')](_0x16e2df['stack']);if(_0x16e2df[_0x610f('0x37')]){delete _0x16e2df[_0x610f('0x37')];}_0x2fc77c[_0x610f('0x2a')](_0x18a4d0)['send'](_0x16e2df);};}exports[_0x610f('0x38')]=function(_0x4d18e9,_0x1b5631){var _0x162e68={},_0xf48fa={},_0x55cc99={'count':0x0,'rows':[]};var _0x4e036b=_['map'](db['VoiceContext'][_0x610f('0x39')],function(_0x5430b1){return{'name':_0x5430b1[_0x610f('0x3a')],'type':_0x5430b1[_0x610f('0x3b')][_0x610f('0x3c')]};});_0xf48fa[_0x610f('0x3d')]=_['map'](_0x4e036b,_0x610f('0x37'));_0xf48fa['query']=_[_0x610f('0x3e')](_0x4d18e9[_0x610f('0x3f')]);_0xf48fa[_0x610f('0x40')]=_['intersection'](_0xf48fa[_0x610f('0x3d')],_0xf48fa[_0x610f('0x3f')]);_0x162e68[_0x610f('0x41')]=_['intersection'](_0xf48fa[_0x610f('0x3d')],qs['fields'](_0x4d18e9['query'][_0x610f('0x42')]));_0x162e68[_0x610f('0x41')]=_0x162e68['attributes'][_0x610f('0x43')]?_0x162e68[_0x610f('0x41')]:_0xf48fa[_0x610f('0x3d')];if(!_0x4d18e9['query'][_0x610f('0x44')](_0x610f('0x45'))){_0x162e68[_0x610f('0x46')]=qs[_0x610f('0x46')](_0x4d18e9[_0x610f('0x3f')][_0x610f('0x46')]);_0x162e68[_0x610f('0x2d')]=qs[_0x610f('0x2d')](_0x4d18e9[_0x610f('0x3f')][_0x610f('0x2d')]);}_0x162e68[_0x610f('0x47')]=qs[_0x610f('0x48')](_0x4d18e9[_0x610f('0x3f')][_0x610f('0x48')]);_0x162e68[_0x610f('0x49')]=qs[_0x610f('0x40')](_[_0x610f('0x4a')](_0x4d18e9[_0x610f('0x3f')],_0xf48fa[_0x610f('0x40')]),_0x4e036b);if(_0x4d18e9[_0x610f('0x3f')][_0x610f('0x4b')]){_0x162e68[_0x610f('0x49')]=_['merge'](_0x162e68[_0x610f('0x49')],{'$or':_[_0x610f('0x4c')](_0x4e036b,function(_0x2f1d41){if(_0x2f1d41[_0x610f('0x3b')]!==_0x610f('0x4d')){var _0x59e7d2={};_0x59e7d2[_0x2f1d41[_0x610f('0x37')]]={'$like':'%'+_0x4d18e9[_0x610f('0x3f')][_0x610f('0x4b')]+'%'};return _0x59e7d2;}})});}_0x162e68=_[_0x610f('0x4e')]({},_0x162e68,_0x4d18e9[_0x610f('0x4f')]);var _0x8264e={'where':_0x162e68[_0x610f('0x49')]};return db[_0x610f('0x50')][_0x610f('0x2f')](_0x8264e)[_0x610f('0x1e')](function(_0x473016){_0x55cc99[_0x610f('0x2f')]=_0x473016;if(_0x4d18e9[_0x610f('0x3f')][_0x610f('0x51')]){_0x162e68[_0x610f('0x52')]=[{'all':!![]}];}return db[_0x610f('0x50')][_0x610f('0x53')](_0x162e68);})[_0x610f('0x1e')](function(_0x93fa86){_0x55cc99[_0x610f('0x54')]=_0x93fa86;return _0x55cc99;})[_0x610f('0x1e')](respondWithFilteredResult(_0x1b5631,_0x162e68))[_0x610f('0x28')](handleError(_0x1b5631,null));};exports[_0x610f('0x55')]=function(_0x7be4e1,_0x24bc85){var _0x57b62f={'raw':![],'where':{'id':_0x7be4e1[_0x610f('0x56')]['id']}},_0x3b92c9={};_0x3b92c9[_0x610f('0x3d')]=_['keys'](db[_0x610f('0x50')][_0x610f('0x39')]);_0x3b92c9[_0x610f('0x3f')]=_[_0x610f('0x3e')](_0x7be4e1['query']);_0x3b92c9[_0x610f('0x40')]=_[_0x610f('0x57')](_0x3b92c9[_0x610f('0x3d')],_0x3b92c9['query']);_0x57b62f[_0x610f('0x41')]=_['intersection'](_0x3b92c9['model'],qs[_0x610f('0x42')](_0x7be4e1[_0x610f('0x3f')][_0x610f('0x42')]));_0x57b62f[_0x610f('0x41')]=_0x57b62f[_0x610f('0x41')][_0x610f('0x43')]?_0x57b62f[_0x610f('0x41')]:_0x3b92c9[_0x610f('0x3d')];if(_0x7be4e1[_0x610f('0x3f')]['includeAll']){_0x57b62f[_0x610f('0x52')]=[{'all':!![]}];}_0x57b62f=_['merge']({},_0x57b62f,_0x7be4e1[_0x610f('0x4f')]);return db[_0x610f('0x50')][_0x610f('0x58')](_0x57b62f)[_0x610f('0x1e')](handleEntityNotFound(_0x24bc85,null))[_0x610f('0x1e')](respondWithResult(_0x24bc85,null))[_0x610f('0x28')](handleError(_0x24bc85,null));};exports[_0x610f('0x59')]=function(_0x4d1d78,_0x1583f3,_0x5a464a){var _0x556a00;return db[_0x610f('0x50')][_0x610f('0x59')](_0x4d1d78[_0x610f('0x5a')],{'raw':!![]})[_0x610f('0x1e')](function(_0x4fb904){_0x556a00=_0x4fb904;return db[_0x610f('0x50')][_0x610f('0x53')]({'raw':!![]});})[_0x610f('0x1e')](function(_0x4aa682){var _0x35b122=fs[_0x610f('0x5b')](path[_0x610f('0x5c')](config[_0x610f('0x5d')],_0x610f('0x5e')),_0x610f('0x5f'));var _0x5b418f=ejs[_0x610f('0x60')](_0x35b122,{'contexts':_0x4aa682||[]});fs[_0x610f('0x61')]('/etc/asterisk/extensions_xcally_contexts.conf',_0x5b418f);})[_0x610f('0x1e')](function(){return respondWithRpcPromise(_0x610f('0x62'),'create',{'module':_0x610f('0x63')});})[_0x610f('0x1e')](function(){var _0x453c0f=_0x4d1d78[_0x610f('0x64')][_0x610f('0x34')]({'plain':!![]});if(!_0x453c0f)throw new Error(_0x610f('0x65'));if(_0x453c0f[_0x610f('0x66')]==='user'){var _0x3ccfac=_0x556a00[_0x610f('0x34')]({'plain':!![]});return db[_0x610f('0x67')][_0x610f('0x58')]({'where':{'name':_0x610f('0x35'),'userProfileId':_0x453c0f[_0x610f('0x68')]},'raw':!![]})['then'](function(_0x2d3750){if(_0x2d3750&&_0x2d3750[_0x610f('0x69')]===0x0){return db['UserProfileResource'][_0x610f('0x59')]({'name':_0x3ccfac[_0x610f('0x37')],'resourceId':_0x3ccfac['id'],'type':_0x2d3750[_0x610f('0x37')],'sectionId':_0x2d3750['id']},{})['then'](function(){return _0x556a00;});}else{return _0x556a00;}})['catch'](function(_0x1cd568){logger['error'](_0x610f('0x6a'),_0x1cd568);throw _0x1cd568;});}return _0x556a00;})[_0x610f('0x1e')](respondWithResult(_0x1583f3,0xc9))['catch'](handleError(_0x1583f3,null));};exports[_0x610f('0x6b')]=function(_0x62c8a,_0x5ccaf0,_0x3aefa8){var _0x924f03;return db['VoiceContext'][_0x610f('0x58')]({'where':{'id':_0x62c8a['params']['id']}})[_0x610f('0x1e')](handleEntityNotFound(_0x5ccaf0,null))['then'](saveUpdates(_0x62c8a['body'],null))[_0x610f('0x1e')](function(_0x5abce5){if(_0x5abce5){_0x924f03=_0x5abce5;return db[_0x610f('0x50')][_0x610f('0x53')]({'raw':!![]});}})[_0x610f('0x1e')](function(_0x555ab4){var _0x22389b=fs['readFileSync'](path[_0x610f('0x5c')](config['root'],_0x610f('0x5e')),'utf8');var _0x2474f0=ejs['render'](_0x22389b,{'contexts':_0x555ab4||[]});fs['writeFileSync'](_0x610f('0x6c'),_0x2474f0);})['then'](function(){return respondWithRpcPromise(_0x610f('0x62'),_0x610f('0x6b'),{'module':'chan_sip.so'});})[_0x610f('0x1e')](function(){return _0x924f03;})[_0x610f('0x1e')](respondWithResult(_0x5ccaf0,null))[_0x610f('0x28')](handleError(_0x5ccaf0,null));};exports[_0x610f('0x33')]=function(_0x161d17,_0x41f150,_0x2b9e39){var _0x400dbe;return db['VoiceContext']['find']({'where':{'id':_0x161d17[_0x610f('0x56')]['id']}})[_0x610f('0x1e')](handleEntityNotFound(_0x41f150,null))['then'](removeEntity(_0x41f150,null))['then'](function(){return db['VoiceContext'][_0x610f('0x53')]({'raw':!![]});})['then'](function(_0x192ce5){var _0x1269e1=fs[_0x610f('0x5b')](path[_0x610f('0x5c')](config[_0x610f('0x5d')],'server/files/templates/context.ejs'),_0x610f('0x5f'));var _0x553b44=ejs[_0x610f('0x60')](_0x1269e1,{'contexts':_0x192ce5});fs[_0x610f('0x61')](_0x610f('0x6c'),_0x553b44);return respondWithRpcPromise(_0x610f('0x62'),_0x610f('0x33'),{'module':_0x610f('0x63')});})[_0x610f('0x28')](handleError(_0x41f150,null));};
\ No newline at end of file