Built motion from commit f7863d46.|2.5.41
[motion2.git] / server / api / user / user.rpc.js
index 1e94d02..3bad44b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x581f=['push','LogoutUser','findOne','destroy','LoginUser','mobile','phone','count','agent','../../config/license/util','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','upsert','loginInPause','all','merge','LOGIN','callysquare','LOGININPAUSE','bulkCreate','concat','util','moment','../../mysqldb','../../config/utils','../../config/logger','client','http','defaults','redis','socket.io-emitter','./user.socket','register','request','then','User,\x20%s,\x20%s','User,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','findAll','options','raw','where','attributes','limit','include','map','model','GetUser','debug','ShowUser','User','PauseUser','internal','UserVoiceQueueRt','update','MemberReport','name','PAUSE','length','getChannels','forEach','isNil','interface','format','SIP/%s','YYYY-MM-DD\x20HH:mm:ss','body','type','role','DEFAULT\x20PAUSE','channel','system','mail','chat','sms','whatsapp','find','set','%s%s','Pause'];(function(_0x4e9d3c,_0x1f4b98){var _0x2d0825=function(_0x384676){while(--_0x384676){_0x4e9d3c['push'](_0x4e9d3c['shift']());}};_0x2d0825(++_0x1f4b98);}(_0x581f,0x6d));var _0xf581=function(_0x14bf67,_0x49df21){_0x14bf67=_0x14bf67-0x0;var _0xe26936=_0x581f[_0x14bf67];return _0xe26936;};'use strict';var _=require('lodash');var util=require(_0xf581('0x0'));var moment=require(_0xf581('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0xf581('0x2'))['db'];var utils=require(_0xf581('0x3'));var logger=require(_0xf581('0x4'))('rpc');var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xf581('0x5')][_0xf581('0x6')]({'port':0x232a});config['redis']=_[_0xf581('0x7')](config[_0xf581('0x8')],{'host':'localhost','port':0x18eb});var socket=require(_0xf581('0x9'))(new Redis(config['redis']));require(_0xf581('0xa'))[_0xf581('0xb')](socket);function respondWithRpcPromise(_0x19ba01,_0x44f3d7,_0x52f0e7){return new BPromise(function(_0x303147,_0x119399){return client[_0xf581('0xc')](_0x19ba01,_0x52f0e7)[_0xf581('0xd')](function(_0x3160e4){logger['info'](_0xf581('0xe'),_0x44f3d7,'request\x20sent');logger['debug'](_0xf581('0xf'),_0x44f3d7,_0xf581('0x10'),JSON[_0xf581('0x11')](_0x3160e4));if(_0x3160e4['error']){if(_0x3160e4[_0xf581('0x12')][_0xf581('0x13')]===0x1f4){logger[_0xf581('0x12')](_0xf581('0xe'),_0x44f3d7,_0x3160e4[_0xf581('0x12')][_0xf581('0x14')]);return _0x119399(_0x3160e4[_0xf581('0x12')][_0xf581('0x14')]);}logger[_0xf581('0x12')](_0xf581('0xe'),_0x44f3d7,_0x3160e4[_0xf581('0x12')][_0xf581('0x14')]);return _0x303147(_0x3160e4[_0xf581('0x12')][_0xf581('0x14')]);}else{logger[_0xf581('0x15')](_0xf581('0xe'),_0x44f3d7,_0xf581('0x10'));_0x303147(_0x3160e4['result'][_0xf581('0x14')]);}})[_0xf581('0x16')](function(_0x7e1220){logger[_0xf581('0x12')](_0xf581('0xe'),_0x44f3d7,_0x7e1220);_0x119399(_0x7e1220);});});}exports['GetUser']=function(_0x1a5a7a){var _0x163fa4=this;return new Promise(function(_0x4de875,_0xf0df36){return db['User'][_0xf581('0x17')]({'raw':_0x1a5a7a[_0xf581('0x18')]?_0x1a5a7a['options'][_0xf581('0x19')]===undefined?!![]:![]:!![],'where':_0x1a5a7a[_0xf581('0x18')]?_0x1a5a7a[_0xf581('0x18')][_0xf581('0x1a')]||null:null,'attributes':_0x1a5a7a['options']?_0x1a5a7a['options'][_0xf581('0x1b')]||null:null,'limit':_0x1a5a7a['options']?_0x1a5a7a[_0xf581('0x18')][_0xf581('0x1c')]||null:null,'include':_0x1a5a7a['options']?_0x1a5a7a[_0xf581('0x18')][_0xf581('0x1d')]?_[_0xf581('0x1e')](_0x1a5a7a['options']['include'],function(_0x582b25){return{'model':db[_0x582b25[_0xf581('0x1f')]],'as':_0x582b25['as'],'attributes':_0x582b25[_0xf581('0x1b')],'include':_0x582b25[_0xf581('0x1d')]?_[_0xf581('0x1e')](_0x582b25[_0xf581('0x1d')],function(_0x3889bb){return{'model':db[_0x3889bb[_0xf581('0x1f')]],'as':_0x3889bb['as'],'attributes':_0x3889bb[_0xf581('0x1b')],'include':_0x3889bb[_0xf581('0x1d')]?_[_0xf581('0x1e')](_0x3889bb['include'],function(_0xb10de0){return{'model':db[_0xb10de0[_0xf581('0x1f')]],'as':_0xb10de0['as'],'attributes':_0xb10de0[_0xf581('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xf581('0xd')](function(_0x13a0bb){logger['info'](_0xf581('0x20'),_0x1a5a7a);logger[_0xf581('0x21')](_0xf581('0x20'),_0x1a5a7a,JSON['stringify'](_0x13a0bb));_0x4de875(_0x13a0bb);})[_0xf581('0x16')](function(_0x2d7662){logger['error'](_0xf581('0x20'),_0x2d7662[_0xf581('0x14')],_0x1a5a7a);_0xf0df36(_0x163fa4[_0xf581('0x12')](0x1f4,_0x2d7662['message']));});});};exports[_0xf581('0x22')]=function(_0x587a6d){var _0xca0aae=this;return new Promise(function(_0x1aab93,_0xf59f63){return db[_0xf581('0x23')]['find']({'raw':_0x587a6d[_0xf581('0x18')]?_0x587a6d[_0xf581('0x18')][_0xf581('0x19')]===undefined?!![]:![]:!![],'where':_0x587a6d[_0xf581('0x18')]?_0x587a6d[_0xf581('0x18')][_0xf581('0x1a')]||null:null,'attributes':_0x587a6d[_0xf581('0x18')]?_0x587a6d['options'][_0xf581('0x1b')]||null:null,'include':_0x587a6d[_0xf581('0x18')]?_0x587a6d['options'][_0xf581('0x1d')]?_[_0xf581('0x1e')](_0x587a6d[_0xf581('0x18')]['include'],function(_0x22ce51){return{'model':db[_0x22ce51['model']],'as':_0x22ce51['as'],'attributes':_0x22ce51[_0xf581('0x1b')],'include':_0x22ce51['include']?_['map'](_0x22ce51[_0xf581('0x1d')],function(_0x3aa527){return{'model':db[_0x3aa527['model']],'as':_0x3aa527['as'],'attributes':_0x3aa527[_0xf581('0x1b')],'include':_0x3aa527['include']?_['map'](_0x3aa527['include'],function(_0x58d92f){return{'model':db[_0x58d92f['model']],'as':_0x58d92f['as'],'attributes':_0x58d92f[_0xf581('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xf581('0xd')](function(_0x2efa2a){logger[_0xf581('0x15')]('ShowUser',_0x587a6d);logger[_0xf581('0x21')](_0xf581('0x22'),_0x587a6d,JSON[_0xf581('0x11')](_0x2efa2a));_0x1aab93(_0x2efa2a);})[_0xf581('0x16')](function(_0x4201ec){logger[_0xf581('0x12')](_0xf581('0x22'),_0x4201ec['message'],_0x587a6d);_0xf59f63(_0xca0aae[_0xf581('0x12')](0x1f4,_0x4201ec[_0xf581('0x14')]));});});};exports[_0xf581('0x24')]=function(_0x5c20b1){var _0x2fcb24=this;return new Promise(function(_0x21eb08,_0x34c9ff){var _0xf1d6c3;return db[_0xf581('0x23')]['find']({'where':_0x5c20b1[_0xf581('0x18')][_0xf581('0x1a')]||{},'attributes':['id','name','role',_0xf581('0x25'),'interface']})['then'](function(_0x337d6e){if(_0x337d6e){_0xf1d6c3=_0x337d6e;return db[_0xf581('0x26')][_0xf581('0x27')]({'paused':0x1},{'where':{'UserId':_0xf1d6c3['id']},'individualHooks':!![]});}})['then'](function(){if(_0xf1d6c3){return db[_0xf581('0x28')]['findAll']({'where':{'membername':_0xf1d6c3[_0xf581('0x29')],'type':_0xf581('0x2a'),'exitAt':null}});}})[_0xf581('0xd')](function(_0x3eda5a){if(_0xf1d6c3){if(_0x3eda5a&&_0x3eda5a['length']){var _0x4b0406=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');for(var _0x57ce53=0x0,_0x43273b=_0x3eda5a[_0xf581('0x2b')];_0x57ce53<_0x43273b;_0x57ce53++){_0x3eda5a[_0x57ce53]['updateAttributes']({'exitAt':_0x4b0406});}}}})[_0xf581('0xd')](function(){if(_0xf1d6c3){var _0xa5e794=[];var _0x5436db=utils[_0xf581('0x2c')]();_0x5436db[_0xf581('0x2d')](function(_0x20baeb){_0xa5e794['push']({'channel':_0x20baeb,'membername':_0xf1d6c3[_0xf581('0x29')],'interface':_[_0xf581('0x2e')](_0xf1d6c3[_0xf581('0x2f')])?util[_0xf581('0x30')](_0xf581('0x31'),_0xf1d6c3[_0xf581('0x29')]):_0xf1d6c3[_0xf581('0x2f')],'type':_0xf581('0x2a'),'enterAt':moment()['format'](_0xf581('0x32')),'data1':_0x5c20b1[_0xf581('0x33')][_0xf581('0x34')]||'DEFAULT\x20PAUSE','role':_0xf1d6c3[_0xf581('0x35')],'internal':_0xf1d6c3[_0xf581('0x25')],'uniqueid':_0x5c20b1['body']['uniqueid']||null});});return db[_0xf581('0x28')]['bulkCreate'](_0xa5e794,{'individualHooks':!![]});}})[_0xf581('0xd')](function(){if(_0xf1d6c3){return _0xf1d6c3[_0xf581('0x27')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x5c20b1[_0xf581('0x33')][_0xf581('0x34')]||_0xf581('0x36'),'lastPauseAt':moment()['format'](_0xf581('0x32'))});}})[_0xf581('0xd')](function(_0x27fd45){_0x21eb08(_0x27fd45);})[_0xf581('0x16')](function(_0x38af95){_0x34c9ff(_0x2fcb24[_0xf581('0x12')](0x1f4,_0x38af95[_0xf581('0x14')]));});});};exports['UnpauseUser']=function(_0x3e4b99){var _0x3607c0=this;return new Promise(function(_0x588804,_0x1fe8f2){var _0x5f554e;return db['User']['findOne']({'where':_0x3e4b99[_0xf581('0x18')][_0xf581('0x1a')]||{},'attributes':['id',_0xf581('0x29')]})['then'](function(_0x1eb1a8){if(_0x1eb1a8){_0x5f554e=_0x1eb1a8;if(_0x3e4b99[_0xf581('0x33')][_0xf581('0x37')]&&!utils['isValidChannel'](_0x3e4b99[_0xf581('0x33')]['channel'])){throw new Error('Unknown\x20channel');}switch(_0x3e4b99[_0xf581('0x33')][_0xf581('0x37')]){case'voice':return db[_0xf581('0x26')][_0xf581('0x27')]({'paused':0x0},{'where':{'UserId':_0x5f554e['id']}})['then'](function(){return db[_0xf581('0x28')]['find']({'where':{'channel':_0x3e4b99[_0xf581('0x33')]['channel'],'membername':_0x5f554e[_0xf581('0x29')],'type':'PAUSE','exitAt':null}});})['then'](function(_0x5d0c2d){if(_0x5d0c2d){return _0x5d0c2d[_0xf581('0x27')]({'exitAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'data2':_0xf581('0x38')},{'individualHooks':!![]});}return null;})['then'](function(){return _0x5f554e['update']({'voicePause':![]});});case _0xf581('0x39'):case _0xf581('0x3a'):case'fax':case _0xf581('0x3b'):case'openchannel':case _0xf581('0x3c'):return db[_0xf581('0x28')][_0xf581('0x3d')]({'where':{'channel':_0x3e4b99[_0xf581('0x33')][_0xf581('0x37')],'membername':_0x5f554e[_0xf581('0x29')],'type':'PAUSE','exitAt':null}})[_0xf581('0xd')](function(_0x43055d){return _0x43055d[_0xf581('0x27')]({'exitAt':moment()[_0xf581('0x30')](_0xf581('0x32')),'data2':_0xf581('0x38')},{'individualHooks':!![]});})[_0xf581('0xd')](function(){var _0x29f732={};_[_0xf581('0x3e')](_0x29f732,util[_0xf581('0x30')](_0xf581('0x3f'),_0x3e4b99[_0xf581('0x33')][_0xf581('0x37')],_0xf581('0x40')),![]);return _0x5f554e[_0xf581('0x27')](_0x29f732);});default:return db[_0xf581('0x26')][_0xf581('0x27')]({'paused':0x0},{'where':{'UserId':_0x5f554e['id']}})['then'](function(){return db[_0xf581('0x28')][_0xf581('0x17')]({'where':{'membername':_0x5f554e[_0xf581('0x29')],'type':'PAUSE','exitAt':null}});})[_0xf581('0xd')](function(_0x58207f){var _0x3b67f1=[];_0x58207f[_0xf581('0x2d')](function(_0x5dbcbc){_0x3b67f1[_0xf581('0x41')](_0x5dbcbc[_0xf581('0x27')]({'exitAt':moment()[_0xf581('0x30')](_0xf581('0x32')),'data2':_0xf581('0x38')}));});return BPromise['all'](_0x3b67f1);})[_0xf581('0xd')](function(){return _0x5f554e['update']({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0xf581('0xd')](function(_0x3a92ce){_0x588804(_0x3a92ce);})[_0xf581('0x16')](function(_0x29ffd8){_0x1fe8f2(_0x3607c0[_0xf581('0x12')](0x1f4,_0x29ffd8[_0xf581('0x14')]));});});};exports[_0xf581('0x42')]=function(_0x798445){var _0x251362=this;return new Promise(function(_0x3c1610,_0x25da8f){var _0x460629;return db[_0xf581('0x23')][_0xf581('0x43')]({'where':_0x798445[_0xf581('0x18')]['where']||{},'attributes':['id','name']})[_0xf581('0xd')](function(_0xcdd713){if(_0xcdd713){_0x460629=_0xcdd713;return db['UserVoiceQueueRt'][_0xf581('0x44')]({'where':{'membername':_0x460629[_0xf581('0x29')]},'individualHooks':!![]});}})['then'](function(){if(_0x460629){return db['MemberReport'][_0xf581('0x17')]({'where':{'membername':_0x460629[_0xf581('0x29')],'exitAt':null}});}})['then'](function(_0x580b81){if(_0x460629){if(_0x580b81&&_0x580b81[_0xf581('0x2b')]){var _0x866700=[];_0x580b81['forEach'](function(_0x253800){_0x866700[_0xf581('0x41')](_0x253800[_0xf581('0x27')]({'exitAt':moment()['format'](_0xf581('0x32'))}));});return BPromise['all'](_0x866700);}}})[_0xf581('0xd')](function(){if(_0x460629){return _0x460629[_0xf581('0x27')]({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xf581('0xd')](function(_0x5e6b4a){_0x3c1610(_0x5e6b4a);})[_0xf581('0x16')](function(_0x155f57){_0x25da8f(_0x251362[_0xf581('0x12')](0x1f4,_0x155f57[_0xf581('0x14')]));});});};exports[_0xf581('0x45')]=function(_0x5bd0fa){var _0x1059bc=this;return new Promise(function(_0x284e6f,_0x40ba15){var _0x3265d2;var _0x30131a;var _0x16fc82;var _0x584bfc;return db[_0xf581('0x23')][_0xf581('0x43')]({'where':_0x5bd0fa[_0xf581('0x18')][_0xf581('0x1a')]||{},'attributes':['id',_0xf581('0x29'),_0xf581('0x35'),_0xf581('0x46'),_0xf581('0x47'),'internal','loginInPause',_0xf581('0x2f')]})[_0xf581('0xd')](function(_0x543ec4){if(_0x543ec4){_0x3265d2=_0x543ec4;_0x584bfc=_0x5bd0fa[_0xf581('0x33')]['interface']?_0x5bd0fa[_0xf581('0x33')]['interface']:util['format']('SIP/%s',_0x3265d2[_0xf581('0x29')]);return db['User'][_0xf581('0x48')]({'where':{'role':_0xf581('0x49'),'online':!![],'id':{'$ne':_0x3265d2['id']}}});}})[_0xf581('0xd')](function(_0x2bd9d2){if(_0x2bd9d2){_0x16fc82=_0x2bd9d2;return require(_0xf581('0x4a'))[_0xf581('0x4b')]();}})['then'](function(_0x3e83ad){if(_0x3e83ad&&_0x3e83ad[_0xf581('0x4c')]&&_0x16fc82>=_0x3e83ad['agents']){throw new Error(_0xf581('0x4d'));}})[_0xf581('0xd')](function(){if(_0x3265d2){return db[_0xf581('0x26')][_0xf581('0x44')]({'where':{'membername':_0x3265d2[_0xf581('0x29')]},'individualHooks':!![]});}})[_0xf581('0xd')](function(){if(_0x3265d2){return _0x3265d2['getVoiceQueues']({'raw':!![]});}})[_0xf581('0xd')](function(_0x3d5f21){if(_0x3265d2){if(_0x3d5f21){var _0xa1ac7c=[];_0x30131a=_0x3d5f21;if(_0x30131a[_0xf581('0x2b')]){for(var _0xc787f6=0x0;_0xc787f6<_0x30131a[_0xf581('0x2b')];_0xc787f6++){_0xa1ac7c[_0xf581('0x41')](db[_0xf581('0x26')][_0xf581('0x4e')]({'membername':_0x3265d2[_0xf581('0x29')],'UserId':_0x3265d2['id'],'queue_name':_0x30131a[_0xc787f6]['name'],'VoiceQueueId':_0x30131a[_0xc787f6]['id'],'interface':_0x584bfc,'paused':_0x3265d2[_0xf581('0x4f')]||![],'penalty':_0x30131a[_0xc787f6]['UserVoiceQueue.penalty']||0x0}));}return BPromise['all'](_0xa1ac7c);}}}})[_0xf581('0xd')](function(){if(_0x3265d2){return db[_0xf581('0x28')][_0xf581('0x17')]({'where':{'membername':_0x3265d2[_0xf581('0x29')],'exitAt':null}});}})[_0xf581('0xd')](function(_0x4e1cfe){if(_0x3265d2){if(_0x4e1cfe&&_0x4e1cfe[_0xf581('0x2b')]){var _0x4c58e6=[];_0x4e1cfe[_0xf581('0x2d')](function(_0x62c87b){_0x4c58e6[_0xf581('0x41')](_0x62c87b[_0xf581('0x27')]({'exitAt':moment()[_0xf581('0x30')](_0xf581('0x32'))}));});return BPromise[_0xf581('0x50')](_0x4c58e6);}}})[_0xf581('0xd')](function(_0x4d088f){if(_0x3265d2){var _0x56c48c=[];var _0x1cb8d1=[];var _0x49c5b3=utils[_0xf581('0x2c')]();var _0x142ffd={'membername':_0x3265d2['name'],'interface':_0x584bfc,'enterAt':moment()[_0xf581('0x30')](_0xf581('0x32')),'role':_0x3265d2[_0xf581('0x35')],'internal':_0x3265d2[_0xf581('0x25')]};_0x49c5b3[_0xf581('0x2d')](function(_0xa6b981){_0x56c48c[_0xf581('0x41')](_[_0xf581('0x51')]({'channel':_0xa6b981,'type':_0xf581('0x52'),'data1':_0xf581('0x53'),'data2':_0x584bfc},_0x142ffd));if(_0x3265d2[_0xf581('0x4f')]){_0x1cb8d1[_0xf581('0x41')](_[_0xf581('0x51')]({'channel':_0xa6b981,'type':_0xf581('0x2a'),'data1':_0xf581('0x54')},_0x142ffd));}});return db[_0xf581('0x28')][_0xf581('0x55')](_0x56c48c[_0xf581('0x56')](_0x1cb8d1),{'individualHooks':!![]});}})[_0xf581('0xd')](function(){if(_0x3265d2){return _0x3265d2[_0xf581('0x27')]({'online':!![],'lastLoginAt':moment()['format'](_0xf581('0x32')),'voicePause':_0x3265d2[_0xf581('0x4f')]||![],'mailPause':_0x3265d2['loginInPause']||![],'chatPause':_0x3265d2['loginInPause']||![],'faxPause':_0x3265d2[_0xf581('0x4f')]||![],'smsPause':_0x3265d2[_0xf581('0x4f')]||![],'openchannelPause':_0x3265d2['loginInPause']||![],'pauseType':_0x3265d2['loginInPause']?_0xf581('0x54'):null,'lastPauseAt':moment()[_0xf581('0x30')](_0xf581('0x32')),'interface':_0x584bfc});}})[_0xf581('0xd')](function(_0x183398){_0x284e6f(_0x183398);})[_0xf581('0x16')](function(_0x102e86){_0x40ba15(_0x1059bc['error'](0x1f4,_0x102e86['message']));});});};
\ No newline at end of file
+var _0x620c=['error','code','message','result','catch','GetUser','findAll','raw','options','attributes','limit','include','model','map','then','stringify','ShowUser','User','where','PauseUser','role','internal','interface','update','name','PAUSE','length','format','YYYY-MM-DD\x20HH:mm:ss','forEach','push','isNil','SIP/%s','type','DEFAULT\x20PAUSE','body','uniqueid','MemberReport','bulkCreate','UnpauseUser','findOne','channel','Unknown\x20channel','voice','UserVoiceQueueRt','find','system','chat','openchannel','whatsapp','set','Pause','all','destroy','mobile','phone','loginInPause','agent','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','UserVoiceQueue.penalty','callysquare','LOGININPAUSE','concat','lodash','moment','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','http','redis','defaults','localhost','socket.io-emitter','register','request','info','User,\x20%s,\x20%s','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s'];(function(_0x3148bc,_0x18727c){var _0x3a9314=function(_0x2c637a){while(--_0x2c637a){_0x3148bc['push'](_0x3148bc['shift']());}};_0x3a9314(++_0x18727c);}(_0x620c,0xf1));var _0xc620=function(_0xdbb1e3,_0x2e28de){_0xdbb1e3=_0xdbb1e3-0x0;var _0xd00914=_0x620c[_0xdbb1e3];return _0xd00914;};'use strict';var _=require(_0xc620('0x0'));var util=require('util');var moment=require(_0xc620('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xc620('0x2'));var db=require(_0xc620('0x3'))['db'];var utils=require(_0xc620('0x4'));var logger=require(_0xc620('0x5'))(_0xc620('0x6'));var config=require(_0xc620('0x7'));var jayson=require('jayson/promise');var client=jayson['client'][_0xc620('0x8')]({'port':0x232a});config[_0xc620('0x9')]=_[_0xc620('0xa')](config[_0xc620('0x9')],{'host':_0xc620('0xb'),'port':0x18eb});var socket=require(_0xc620('0xc'))(new Redis(config[_0xc620('0x9')]));require('./user.socket')[_0xc620('0xd')](socket);function respondWithRpcPromise(_0x3efe55,_0x48031d,_0x38d4ee){return new BPromise(function(_0x9b8153,_0x1552fc){return client[_0xc620('0xe')](_0x3efe55,_0x38d4ee)['then'](function(_0xf44fe7){logger[_0xc620('0xf')](_0xc620('0x10'),_0x48031d,_0xc620('0x11'));logger[_0xc620('0x12')](_0xc620('0x13'),_0x48031d,_0xc620('0x11'),JSON['stringify'](_0xf44fe7));if(_0xf44fe7[_0xc620('0x14')]){if(_0xf44fe7['error'][_0xc620('0x15')]===0x1f4){logger[_0xc620('0x14')](_0xc620('0x10'),_0x48031d,_0xf44fe7[_0xc620('0x14')][_0xc620('0x16')]);return _0x1552fc(_0xf44fe7['error']['message']);}logger[_0xc620('0x14')](_0xc620('0x10'),_0x48031d,_0xf44fe7[_0xc620('0x14')][_0xc620('0x16')]);return _0x9b8153(_0xf44fe7[_0xc620('0x14')]['message']);}else{logger[_0xc620('0xf')](_0xc620('0x10'),_0x48031d,_0xc620('0x11'));_0x9b8153(_0xf44fe7[_0xc620('0x17')][_0xc620('0x16')]);}})[_0xc620('0x18')](function(_0x5a735c){logger[_0xc620('0x14')](_0xc620('0x10'),_0x48031d,_0x5a735c);_0x1552fc(_0x5a735c);});});}exports[_0xc620('0x19')]=function(_0x42915c){var _0x46594a=this;return new Promise(function(_0x54a757,_0x3e60a2){return db['User'][_0xc620('0x1a')]({'raw':_0x42915c['options']?_0x42915c['options'][_0xc620('0x1b')]===undefined?!![]:![]:!![],'where':_0x42915c['options']?_0x42915c[_0xc620('0x1c')]['where']||null:null,'attributes':_0x42915c['options']?_0x42915c['options'][_0xc620('0x1d')]||null:null,'limit':_0x42915c['options']?_0x42915c['options'][_0xc620('0x1e')]||null:null,'include':_0x42915c[_0xc620('0x1c')]?_0x42915c[_0xc620('0x1c')][_0xc620('0x1f')]?_['map'](_0x42915c[_0xc620('0x1c')][_0xc620('0x1f')],function(_0x292b9e){return{'model':db[_0x292b9e[_0xc620('0x20')]],'as':_0x292b9e['as'],'attributes':_0x292b9e['attributes'],'include':_0x292b9e[_0xc620('0x1f')]?_['map'](_0x292b9e[_0xc620('0x1f')],function(_0x5c1eda){return{'model':db[_0x5c1eda[_0xc620('0x20')]],'as':_0x5c1eda['as'],'attributes':_0x5c1eda[_0xc620('0x1d')],'include':_0x5c1eda['include']?_[_0xc620('0x21')](_0x5c1eda[_0xc620('0x1f')],function(_0x2f224d){return{'model':db[_0x2f224d[_0xc620('0x20')]],'as':_0x2f224d['as'],'attributes':_0x2f224d['attributes']};}):[]};}):[]};}):[]:[]})[_0xc620('0x22')](function(_0x54b298){logger[_0xc620('0xf')](_0xc620('0x19'),_0x42915c);logger[_0xc620('0x12')](_0xc620('0x19'),_0x42915c,JSON[_0xc620('0x23')](_0x54b298));_0x54a757(_0x54b298);})[_0xc620('0x18')](function(_0x7ce55d){logger['error']('GetUser',_0x7ce55d['message'],_0x42915c);_0x3e60a2(_0x46594a['error'](0x1f4,_0x7ce55d[_0xc620('0x16')]));});});};exports[_0xc620('0x24')]=function(_0x477899){var _0x1ac655=this;return new Promise(function(_0x52324e,_0x1abf9e){return db[_0xc620('0x25')]['find']({'raw':_0x477899[_0xc620('0x1c')]?_0x477899[_0xc620('0x1c')][_0xc620('0x1b')]===undefined?!![]:![]:!![],'where':_0x477899[_0xc620('0x1c')]?_0x477899[_0xc620('0x1c')][_0xc620('0x26')]||null:null,'attributes':_0x477899['options']?_0x477899[_0xc620('0x1c')][_0xc620('0x1d')]||null:null,'include':_0x477899['options']?_0x477899[_0xc620('0x1c')][_0xc620('0x1f')]?_[_0xc620('0x21')](_0x477899[_0xc620('0x1c')][_0xc620('0x1f')],function(_0x5b469f){return{'model':db[_0x5b469f[_0xc620('0x20')]],'as':_0x5b469f['as'],'attributes':_0x5b469f['attributes'],'include':_0x5b469f[_0xc620('0x1f')]?_[_0xc620('0x21')](_0x5b469f[_0xc620('0x1f')],function(_0x1f774e){return{'model':db[_0x1f774e[_0xc620('0x20')]],'as':_0x1f774e['as'],'attributes':_0x1f774e[_0xc620('0x1d')],'include':_0x1f774e['include']?_[_0xc620('0x21')](_0x1f774e['include'],function(_0x3bfdea){return{'model':db[_0x3bfdea[_0xc620('0x20')]],'as':_0x3bfdea['as'],'attributes':_0x3bfdea[_0xc620('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xc620('0x22')](function(_0x5ba652){logger[_0xc620('0xf')](_0xc620('0x24'),_0x477899);logger[_0xc620('0x12')](_0xc620('0x24'),_0x477899,JSON[_0xc620('0x23')](_0x5ba652));_0x52324e(_0x5ba652);})[_0xc620('0x18')](function(_0x32753c){logger[_0xc620('0x14')](_0xc620('0x24'),_0x32753c['message'],_0x477899);_0x1abf9e(_0x1ac655[_0xc620('0x14')](0x1f4,_0x32753c['message']));});});};exports[_0xc620('0x27')]=function(_0x420dfc){var _0x2d99f1=this;return new Promise(function(_0x18535e,_0x48af08){var _0x17a1a3;return db[_0xc620('0x25')]['find']({'where':_0x420dfc[_0xc620('0x1c')][_0xc620('0x26')]||{},'attributes':['id','name',_0xc620('0x28'),_0xc620('0x29'),_0xc620('0x2a')]})[_0xc620('0x22')](function(_0x45a7f6){if(_0x45a7f6){_0x17a1a3=_0x45a7f6;return db['UserVoiceQueueRt'][_0xc620('0x2b')]({'paused':0x1},{'where':{'UserId':_0x17a1a3['id']},'individualHooks':!![]});}})[_0xc620('0x22')](function(){if(_0x17a1a3){return db['MemberReport'][_0xc620('0x1a')]({'where':{'membername':_0x17a1a3[_0xc620('0x2c')],'type':_0xc620('0x2d'),'exitAt':null}});}})[_0xc620('0x22')](function(_0x27eb5e){if(_0x17a1a3){if(_0x27eb5e&&_0x27eb5e[_0xc620('0x2e')]){var _0x174b1f=moment()[_0xc620('0x2f')](_0xc620('0x30'));for(var _0x1b7c16=0x0,_0xaf29cc=_0x27eb5e['length'];_0x1b7c16<_0xaf29cc;_0x1b7c16++){_0x27eb5e[_0x1b7c16]['updateAttributes']({'exitAt':_0x174b1f});}}}})[_0xc620('0x22')](function(){if(_0x17a1a3){var _0xd4cee8=[];var _0xacbf73=utils['getChannels']();_0xacbf73[_0xc620('0x31')](function(_0x4e4cc7){_0xd4cee8[_0xc620('0x32')]({'channel':_0x4e4cc7,'membername':_0x17a1a3[_0xc620('0x2c')],'interface':_[_0xc620('0x33')](_0x17a1a3[_0xc620('0x2a')])?util[_0xc620('0x2f')](_0xc620('0x34'),_0x17a1a3['name']):_0x17a1a3[_0xc620('0x2a')],'type':_0xc620('0x2d'),'enterAt':moment()[_0xc620('0x2f')](_0xc620('0x30')),'data1':_0x420dfc['body'][_0xc620('0x35')]||_0xc620('0x36'),'role':_0x17a1a3[_0xc620('0x28')],'internal':_0x17a1a3['internal'],'uniqueid':_0x420dfc[_0xc620('0x37')][_0xc620('0x38')]||null});});return db[_0xc620('0x39')][_0xc620('0x3a')](_0xd4cee8,{'individualHooks':!![]});}})['then'](function(){if(_0x17a1a3){return _0x17a1a3[_0xc620('0x2b')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x420dfc[_0xc620('0x37')][_0xc620('0x35')]||_0xc620('0x36'),'lastPauseAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')});}})[_0xc620('0x22')](function(_0x42d583){_0x18535e(_0x42d583);})[_0xc620('0x18')](function(_0x1b5b78){_0x48af08(_0x2d99f1['error'](0x1f4,_0x1b5b78[_0xc620('0x16')]));});});};exports[_0xc620('0x3b')]=function(_0x440eb1){var _0x4aa5a7=this;return new Promise(function(_0x29cf36,_0x2d6545){var _0x503c70;return db[_0xc620('0x25')][_0xc620('0x3c')]({'where':_0x440eb1[_0xc620('0x1c')]['where']||{},'attributes':['id',_0xc620('0x2c')]})['then'](function(_0x56dc5c){if(_0x56dc5c){_0x503c70=_0x56dc5c;if(_0x440eb1[_0xc620('0x37')][_0xc620('0x3d')]&&!utils['isValidChannel'](_0x440eb1['body'][_0xc620('0x3d')])){throw new Error(_0xc620('0x3e'));}switch(_0x440eb1[_0xc620('0x37')][_0xc620('0x3d')]){case _0xc620('0x3f'):return db[_0xc620('0x40')][_0xc620('0x2b')]({'paused':0x0},{'where':{'UserId':_0x503c70['id']}})[_0xc620('0x22')](function(){return db[_0xc620('0x39')][_0xc620('0x41')]({'where':{'channel':_0x440eb1[_0xc620('0x37')][_0xc620('0x3d')],'membername':_0x503c70[_0xc620('0x2c')],'type':_0xc620('0x2d'),'exitAt':null}});})['then'](function(_0x54eda7){if(_0x54eda7){return _0x54eda7[_0xc620('0x2b')]({'exitAt':moment()[_0xc620('0x2f')](_0xc620('0x30')),'data2':_0xc620('0x42')},{'individualHooks':!![]});}return null;})['then'](function(){return _0x503c70[_0xc620('0x2b')]({'voicePause':![]});});case'mail':case _0xc620('0x43'):case'fax':case'sms':case _0xc620('0x44'):case _0xc620('0x45'):return db['MemberReport'][_0xc620('0x41')]({'where':{'channel':_0x440eb1[_0xc620('0x37')][_0xc620('0x3d')],'membername':_0x503c70[_0xc620('0x2c')],'type':_0xc620('0x2d'),'exitAt':null}})[_0xc620('0x22')](function(_0x411edf){return _0x411edf[_0xc620('0x2b')]({'exitAt':moment()[_0xc620('0x2f')]('YYYY-MM-DD\x20HH:mm:ss'),'data2':_0xc620('0x42')},{'individualHooks':!![]});})[_0xc620('0x22')](function(){var _0x43d1d0={};_[_0xc620('0x46')](_0x43d1d0,util[_0xc620('0x2f')]('%s%s',_0x440eb1['body']['channel'],_0xc620('0x47')),![]);return _0x503c70[_0xc620('0x2b')](_0x43d1d0);});default:return db[_0xc620('0x40')][_0xc620('0x2b')]({'paused':0x0},{'where':{'UserId':_0x503c70['id']}})[_0xc620('0x22')](function(){return db[_0xc620('0x39')][_0xc620('0x1a')]({'where':{'membername':_0x503c70[_0xc620('0x2c')],'type':_0xc620('0x2d'),'exitAt':null}});})[_0xc620('0x22')](function(_0x10bb2f){var _0x19baaf=[];_0x10bb2f[_0xc620('0x31')](function(_0x257763){_0x19baaf[_0xc620('0x32')](_0x257763[_0xc620('0x2b')]({'exitAt':moment()[_0xc620('0x2f')](_0xc620('0x30')),'data2':_0xc620('0x42')}));});return BPromise[_0xc620('0x48')](_0x19baaf);})['then'](function(){return _0x503c70['update']({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})['then'](function(_0x5ed661){_0x29cf36(_0x5ed661);})[_0xc620('0x18')](function(_0x2cc2e6){_0x2d6545(_0x4aa5a7[_0xc620('0x14')](0x1f4,_0x2cc2e6[_0xc620('0x16')]));});});};exports['LogoutUser']=function(_0x4165c3){var _0x455a26=this;return new Promise(function(_0x585772,_0x2bc914){var _0x1f1edb;return db['User']['findOne']({'where':_0x4165c3[_0xc620('0x1c')][_0xc620('0x26')]||{},'attributes':['id','name']})['then'](function(_0x56cbfa){if(_0x56cbfa){_0x1f1edb=_0x56cbfa;return db['UserVoiceQueueRt'][_0xc620('0x49')]({'where':{'membername':_0x1f1edb[_0xc620('0x2c')]},'individualHooks':!![]});}})['then'](function(){if(_0x1f1edb){return db['MemberReport'][_0xc620('0x1a')]({'where':{'membername':_0x1f1edb[_0xc620('0x2c')],'exitAt':null}});}})['then'](function(_0x4343cc){if(_0x1f1edb){if(_0x4343cc&&_0x4343cc[_0xc620('0x2e')]){var _0x1f475c=[];_0x4343cc[_0xc620('0x31')](function(_0x1e3585){_0x1f475c['push'](_0x1e3585[_0xc620('0x2b')]({'exitAt':moment()[_0xc620('0x2f')](_0xc620('0x30'))}));});return BPromise[_0xc620('0x48')](_0x1f475c);}}})['then'](function(){if(_0x1f1edb){return _0x1f1edb[_0xc620('0x2b')]({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xc620('0x22')](function(_0x211cf9){_0x585772(_0x211cf9);})['catch'](function(_0x56611e){_0x2bc914(_0x455a26[_0xc620('0x14')](0x1f4,_0x56611e[_0xc620('0x16')]));});});};exports['LoginUser']=function(_0x1cc492){var _0x30f953=this;return new Promise(function(_0x1d79ab,_0x269766){var _0x192edc;var _0x270128;var _0x1173b8;var _0x21a6c0;return db[_0xc620('0x25')][_0xc620('0x3c')]({'where':_0x1cc492[_0xc620('0x1c')][_0xc620('0x26')]||{},'attributes':['id',_0xc620('0x2c'),_0xc620('0x28'),_0xc620('0x4a'),_0xc620('0x4b'),_0xc620('0x29'),_0xc620('0x4c'),'interface']})['then'](function(_0x52fa48){if(_0x52fa48){_0x192edc=_0x52fa48;_0x21a6c0=_0x1cc492[_0xc620('0x37')][_0xc620('0x2a')]?_0x1cc492['body'][_0xc620('0x2a')]:util['format']('SIP/%s',_0x192edc['name']);return db[_0xc620('0x25')]['count']({'where':{'role':_0xc620('0x4d'),'online':!![],'id':{'$ne':_0x192edc['id']}}});}})[_0xc620('0x22')](function(_0x1773ad){if(_0x1773ad){_0x1173b8=_0x1773ad;return require('../../config/license/util')[_0xc620('0x4e')]();}})[_0xc620('0x22')](function(_0x10fa76){if(_0x10fa76&&_0x10fa76['agents']&&_0x1173b8>=_0x10fa76[_0xc620('0x4f')]){throw new Error(_0xc620('0x50'));}})[_0xc620('0x22')](function(){if(_0x192edc){return db[_0xc620('0x40')][_0xc620('0x49')]({'where':{'membername':_0x192edc['name']},'individualHooks':!![]});}})[_0xc620('0x22')](function(){if(_0x192edc){return _0x192edc[_0xc620('0x51')]({'raw':!![]});}})[_0xc620('0x22')](function(_0x49e760){if(_0x192edc){if(_0x49e760){var _0x2eaab1=[];_0x270128=_0x49e760;if(_0x270128[_0xc620('0x2e')]){for(var _0xe16d38=0x0;_0xe16d38<_0x270128[_0xc620('0x2e')];_0xe16d38++){_0x2eaab1['push'](db[_0xc620('0x40')][_0xc620('0x52')]({'membername':_0x192edc[_0xc620('0x2c')],'UserId':_0x192edc['id'],'queue_name':_0x270128[_0xe16d38][_0xc620('0x2c')],'VoiceQueueId':_0x270128[_0xe16d38]['id'],'interface':_0x21a6c0,'paused':_0x192edc[_0xc620('0x4c')]||![],'penalty':_0x270128[_0xe16d38][_0xc620('0x53')]||0x0}));}return BPromise[_0xc620('0x48')](_0x2eaab1);}}}})[_0xc620('0x22')](function(){if(_0x192edc){return db[_0xc620('0x39')][_0xc620('0x1a')]({'where':{'membername':_0x192edc[_0xc620('0x2c')],'exitAt':null}});}})[_0xc620('0x22')](function(_0x5d5e35){if(_0x192edc){if(_0x5d5e35&&_0x5d5e35['length']){var _0x3dabaf=[];_0x5d5e35[_0xc620('0x31')](function(_0x2ea933){_0x3dabaf[_0xc620('0x32')](_0x2ea933[_0xc620('0x2b')]({'exitAt':moment()[_0xc620('0x2f')](_0xc620('0x30'))}));});return BPromise['all'](_0x3dabaf);}}})['then'](function(_0x1c7a4f){if(_0x192edc){var _0x12240c=[];var _0x23c656=[];var _0x41d59b=utils['getChannels']();var _0x227b50={'membername':_0x192edc[_0xc620('0x2c')],'interface':_0x21a6c0,'enterAt':moment()[_0xc620('0x2f')](_0xc620('0x30')),'role':_0x192edc[_0xc620('0x28')],'internal':_0x192edc[_0xc620('0x29')]};_0x41d59b[_0xc620('0x31')](function(_0x2f9911){_0x12240c[_0xc620('0x32')](_['merge']({'channel':_0x2f9911,'type':'LOGIN','data1':_0xc620('0x54'),'data2':_0x21a6c0},_0x227b50));if(_0x192edc[_0xc620('0x4c')]){_0x23c656[_0xc620('0x32')](_['merge']({'channel':_0x2f9911,'type':_0xc620('0x2d'),'data1':_0xc620('0x55')},_0x227b50));}});return db[_0xc620('0x39')][_0xc620('0x3a')](_0x12240c[_0xc620('0x56')](_0x23c656),{'individualHooks':!![]});}})[_0xc620('0x22')](function(){if(_0x192edc){return _0x192edc[_0xc620('0x2b')]({'online':!![],'lastLoginAt':moment()[_0xc620('0x2f')](_0xc620('0x30')),'voicePause':_0x192edc[_0xc620('0x4c')]||![],'mailPause':_0x192edc[_0xc620('0x4c')]||![],'chatPause':_0x192edc[_0xc620('0x4c')]||![],'faxPause':_0x192edc[_0xc620('0x4c')]||![],'smsPause':_0x192edc['loginInPause']||![],'openchannelPause':_0x192edc[_0xc620('0x4c')]||![],'pauseType':_0x192edc[_0xc620('0x4c')]?_0xc620('0x55'):null,'lastPauseAt':moment()[_0xc620('0x2f')](_0xc620('0x30')),'interface':_0x21a6c0});}})['then'](function(_0x365138){_0x1d79ab(_0x365138);})['catch'](function(_0x1d9161){_0x269766(_0x30f953[_0xc620('0x14')](0x1f4,_0x1d9161['message']));});});};
\ No newline at end of file