Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / user / user.rpc.js
index 1e94d02..a0e8694 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 _0xcb6d=['PauseUser','find','name','role','interface','UserVoiceQueueRt','update','MemberReport','PAUSE','format','YYYY-MM-DD\x20HH:mm:ss','length','updateAttributes','getChannels','forEach','isNil','SIP/%s','body','internal','uniqueid','type','DEFAULT\x20PAUSE','UnpauseUser','channel','isValidChannel','Channel\x20parameter\x20%s\x20is\x20invalid','findOne','online','voicePause','mailPause','chatPause','openchannelPause','smsPause','whatsappPause','pauseType','lastPauseAt','User\x20with\x20id\x20%s\x20not\x20found','params','unpause','system','LogoutUser','destroy','push','all','LoginUser','mobile','phone','loginInPause','agent','getLicense','agents','getVoiceQueues','UserVoiceQueue.penalty','merge','LOGININPAUSE','bulkCreate','concat','util','moment','bluebird','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','redis','localhost','socket.io-emitter','./user.socket','register','GetUser','User','findAll','options','raw','attributes','limit','include','map','model','then','info','debug','stringify','error','message','ShowUser','where','catch'];(function(_0x43d8d5,_0x419537){var _0x447173=function(_0x26b442){while(--_0x26b442){_0x43d8d5['push'](_0x43d8d5['shift']());}};_0x447173(++_0x419537);}(_0xcb6d,0x19d));var _0xdcb6=function(_0x117e9d,_0x2cc825){_0x117e9d=_0x117e9d-0x0;var _0x5b3544=_0xcb6d[_0x117e9d];return _0x5b3544;};'use strict';var _=require('lodash');var util=require(_0xdcb6('0x0'));var moment=require(_0xdcb6('0x1'));var BPromise=require(_0xdcb6('0x2'));var Redis=require(_0xdcb6('0x3'));var db=require(_0xdcb6('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0xdcb6('0x5'))(_0xdcb6('0x6'));var config=require(_0xdcb6('0x7'));config[_0xdcb6('0x8')]=_['defaults'](config[_0xdcb6('0x8')],{'host':_0xdcb6('0x9'),'port':0x18eb});var socket=require(_0xdcb6('0xa'))(new Redis(config['redis']));require(_0xdcb6('0xb'))[_0xdcb6('0xc')](socket);exports[_0xdcb6('0xd')]=function(_0x1567c4){var _0x1a74a2=this;return new Promise(function(_0x16f2ec,_0x27bfd4){return db[_0xdcb6('0xe')][_0xdcb6('0xf')]({'raw':_0x1567c4[_0xdcb6('0x10')]?_0x1567c4[_0xdcb6('0x10')][_0xdcb6('0x11')]===undefined?!![]:![]:!![],'where':_0x1567c4[_0xdcb6('0x10')]?_0x1567c4[_0xdcb6('0x10')]['where']||null:null,'attributes':_0x1567c4['options']?_0x1567c4[_0xdcb6('0x10')][_0xdcb6('0x12')]||null:null,'limit':_0x1567c4[_0xdcb6('0x10')]?_0x1567c4['options'][_0xdcb6('0x13')]||null:null,'include':_0x1567c4[_0xdcb6('0x10')]?_0x1567c4['options'][_0xdcb6('0x14')]?_[_0xdcb6('0x15')](_0x1567c4[_0xdcb6('0x10')][_0xdcb6('0x14')],function(_0x485bad){return{'model':db[_0x485bad[_0xdcb6('0x16')]],'as':_0x485bad['as'],'attributes':_0x485bad[_0xdcb6('0x12')],'include':_0x485bad[_0xdcb6('0x14')]?_[_0xdcb6('0x15')](_0x485bad[_0xdcb6('0x14')],function(_0x33c133){return{'model':db[_0x33c133[_0xdcb6('0x16')]],'as':_0x33c133['as'],'attributes':_0x33c133['attributes'],'include':_0x33c133[_0xdcb6('0x14')]?_[_0xdcb6('0x15')](_0x33c133['include'],function(_0x38d907){return{'model':db[_0x38d907[_0xdcb6('0x16')]],'as':_0x38d907['as'],'attributes':_0x38d907[_0xdcb6('0x12')]};}):[]};}):[]};}):[]:[]})[_0xdcb6('0x17')](function(_0x59d9a2){logger[_0xdcb6('0x18')](_0xdcb6('0xd'),_0x1567c4);logger[_0xdcb6('0x19')](_0xdcb6('0xd'),_0x1567c4,JSON[_0xdcb6('0x1a')](_0x59d9a2));_0x16f2ec(_0x59d9a2);})['catch'](function(_0x100aee){logger[_0xdcb6('0x1b')]('GetUser',_0x100aee[_0xdcb6('0x1c')],_0x1567c4);_0x27bfd4(_0x1a74a2[_0xdcb6('0x1b')](0x1f4,_0x100aee[_0xdcb6('0x1c')]));});});};exports[_0xdcb6('0x1d')]=function(_0x5f208e){var _0x33d989=this;return new Promise(function(_0x55685a,_0x5106e9){return db[_0xdcb6('0xe')]['find']({'raw':_0x5f208e['options']?_0x5f208e[_0xdcb6('0x10')][_0xdcb6('0x11')]===undefined?!![]:![]:!![],'where':_0x5f208e[_0xdcb6('0x10')]?_0x5f208e[_0xdcb6('0x10')][_0xdcb6('0x1e')]||null:null,'attributes':_0x5f208e[_0xdcb6('0x10')]?_0x5f208e[_0xdcb6('0x10')][_0xdcb6('0x12')]||null:null,'include':_0x5f208e[_0xdcb6('0x10')]?_0x5f208e[_0xdcb6('0x10')]['include']?_['map'](_0x5f208e[_0xdcb6('0x10')][_0xdcb6('0x14')],function(_0x42baa2){return{'model':db[_0x42baa2[_0xdcb6('0x16')]],'as':_0x42baa2['as'],'attributes':_0x42baa2['attributes'],'include':_0x42baa2[_0xdcb6('0x14')]?_[_0xdcb6('0x15')](_0x42baa2[_0xdcb6('0x14')],function(_0x19958d){return{'model':db[_0x19958d['model']],'as':_0x19958d['as'],'attributes':_0x19958d[_0xdcb6('0x12')],'include':_0x19958d['include']?_[_0xdcb6('0x15')](_0x19958d[_0xdcb6('0x14')],function(_0x4ef6d9){return{'model':db[_0x4ef6d9['model']],'as':_0x4ef6d9['as'],'attributes':_0x4ef6d9[_0xdcb6('0x12')]};}):[]};}):[]};}):[]:[]})[_0xdcb6('0x17')](function(_0x250696){logger[_0xdcb6('0x18')](_0xdcb6('0x1d'),_0x5f208e);logger['debug']('ShowUser',_0x5f208e,JSON[_0xdcb6('0x1a')](_0x250696));_0x55685a(_0x250696);})[_0xdcb6('0x1f')](function(_0x22d069){logger[_0xdcb6('0x1b')](_0xdcb6('0x1d'),_0x22d069[_0xdcb6('0x1c')],_0x5f208e);_0x5106e9(_0x33d989[_0xdcb6('0x1b')](0x1f4,_0x22d069[_0xdcb6('0x1c')]));});});};exports[_0xdcb6('0x20')]=function(_0x264eaf){var _0x49060b=this;return new Promise(function(_0x4b6f53,_0x23c285){var _0x1c7295;return db[_0xdcb6('0xe')][_0xdcb6('0x21')]({'where':_0x264eaf['options'][_0xdcb6('0x1e')]||{},'attributes':['id',_0xdcb6('0x22'),_0xdcb6('0x23'),'internal',_0xdcb6('0x24')]})[_0xdcb6('0x17')](function(_0x27ca4f){if(_0x27ca4f){_0x1c7295=_0x27ca4f;return db[_0xdcb6('0x25')][_0xdcb6('0x26')]({'paused':0x1},{'where':{'UserId':_0x1c7295['id']},'individualHooks':!![]});}})['then'](function(){if(_0x1c7295){return db[_0xdcb6('0x27')][_0xdcb6('0xf')]({'where':{'membername':_0x1c7295[_0xdcb6('0x22')],'type':_0xdcb6('0x28'),'exitAt':null}});}})[_0xdcb6('0x17')](function(_0x2c7737){if(_0x1c7295){if(_0x2c7737&&_0x2c7737['length']){var _0x58483b=moment()[_0xdcb6('0x29')](_0xdcb6('0x2a'));for(var _0x481a36=0x0,_0x8a9631=_0x2c7737[_0xdcb6('0x2b')];_0x481a36<_0x8a9631;_0x481a36++){_0x2c7737[_0x481a36][_0xdcb6('0x2c')]({'exitAt':_0x58483b});}}}})[_0xdcb6('0x17')](function(){if(_0x1c7295){var _0x5ed9ed=[];var _0x1ec7d4=utils[_0xdcb6('0x2d')]();_0x1ec7d4[_0xdcb6('0x2e')](function(_0x589ee4){_0x5ed9ed['push']({'channel':_0x589ee4,'membername':_0x1c7295[_0xdcb6('0x22')],'interface':_[_0xdcb6('0x2f')](_0x1c7295[_0xdcb6('0x24')])?util['format'](_0xdcb6('0x30'),_0x1c7295[_0xdcb6('0x22')]):_0x1c7295[_0xdcb6('0x24')],'type':_0xdcb6('0x28'),'enterAt':moment()[_0xdcb6('0x29')](_0xdcb6('0x2a')),'data1':_0x264eaf[_0xdcb6('0x31')]['type']||'DEFAULT\x20PAUSE','role':_0x1c7295[_0xdcb6('0x23')],'internal':_0x1c7295[_0xdcb6('0x32')],'uniqueid':_0x264eaf[_0xdcb6('0x31')][_0xdcb6('0x33')]||null});});return db[_0xdcb6('0x27')]['bulkCreate'](_0x5ed9ed,{'individualHooks':!![]});}})['then'](function(){if(_0x1c7295){return _0x1c7295['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x264eaf[_0xdcb6('0x31')][_0xdcb6('0x34')]||_0xdcb6('0x35'),'lastPauseAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')});}})['then'](function(_0x49fd07){_0x4b6f53(_0x49fd07);})[_0xdcb6('0x1f')](function(_0x3bebc5){_0x23c285(_0x49060b[_0xdcb6('0x1b')](0x1f4,_0x3bebc5['message']));});});};exports[_0xdcb6('0x36')]=function(_0x162fe0){var _0x3537eb=this;return new Promise(function(_0xeb4565,_0x1ea6aa){if(_0x162fe0[_0xdcb6('0x31')][_0xdcb6('0x37')]&&!utils[_0xdcb6('0x38')](_0x162fe0[_0xdcb6('0x31')][_0xdcb6('0x37')])){throw new Error(util['format'](_0xdcb6('0x39'),_0x162fe0[_0xdcb6('0x31')][_0xdcb6('0x37')]));}return db['User'][_0xdcb6('0x3a')]({'where':_0x162fe0[_0xdcb6('0x10')]['where']||{},'attributes':['id',_0xdcb6('0x22'),'role',_0xdcb6('0x32'),_0xdcb6('0x24'),_0xdcb6('0x3b'),_0xdcb6('0x3c'),_0xdcb6('0x3d'),_0xdcb6('0x3e'),'faxPause',_0xdcb6('0x3f'),_0xdcb6('0x40'),_0xdcb6('0x41'),_0xdcb6('0x42'),_0xdcb6('0x43')]})[_0xdcb6('0x17')](function(_0x1419bf){if(!_0x1419bf){throw new Error(util[_0xdcb6('0x29')](_0xdcb6('0x44'),_0x162fe0[_0xdcb6('0x45')]['id']));}return _0x1419bf[_0xdcb6('0x46')](_0x162fe0[_0xdcb6('0x31')][_0xdcb6('0x37')],_0xdcb6('0x47'));})['then'](function(_0x2336d1){_0xeb4565(_0x2336d1);})['catch'](function(_0x5d2278){_0x1ea6aa(_0x3537eb[_0xdcb6('0x1b')](0x1f4,_0x5d2278[_0xdcb6('0x1c')]));});});};exports[_0xdcb6('0x48')]=function(_0x14546d){var _0x28b697=this;return new Promise(function(_0x252a16,_0x440744){var _0x718229;return db['User'][_0xdcb6('0x3a')]({'where':_0x14546d[_0xdcb6('0x10')]['where']||{},'attributes':['id',_0xdcb6('0x22')]})[_0xdcb6('0x17')](function(_0x2a7c30){if(_0x2a7c30){_0x718229=_0x2a7c30;return db[_0xdcb6('0x25')][_0xdcb6('0x49')]({'where':{'membername':_0x718229[_0xdcb6('0x22')]},'individualHooks':!![]});}})[_0xdcb6('0x17')](function(){if(_0x718229){return db[_0xdcb6('0x27')][_0xdcb6('0xf')]({'where':{'membername':_0x718229[_0xdcb6('0x22')],'exitAt':null}});}})[_0xdcb6('0x17')](function(_0xd691db){if(_0x718229){if(_0xd691db&&_0xd691db[_0xdcb6('0x2b')]){var _0x20beb5=[];_0xd691db[_0xdcb6('0x2e')](function(_0x1a5b6e){_0x20beb5[_0xdcb6('0x4a')](_0x1a5b6e[_0xdcb6('0x26')]({'exitAt':moment()[_0xdcb6('0x29')](_0xdcb6('0x2a'))}));});return BPromise[_0xdcb6('0x4b')](_0x20beb5);}}})[_0xdcb6('0x17')](function(){if(_0x718229){return _0x718229[_0xdcb6('0x26')]({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xdcb6('0x17')](function(_0x5cc325){_0x252a16(_0x5cc325);})['catch'](function(_0x3e1a31){_0x440744(_0x28b697[_0xdcb6('0x1b')](0x1f4,_0x3e1a31[_0xdcb6('0x1c')]));});});};exports[_0xdcb6('0x4c')]=function(_0x3fe5fc){var _0x3c7a67=this;return new Promise(function(_0x245f36,_0x454e4b){var _0x1b9e9c;var _0x13f1a4;var _0x3f86c8;var _0x2eeac1;return db['User']['findOne']({'where':_0x3fe5fc[_0xdcb6('0x10')][_0xdcb6('0x1e')]||{},'attributes':['id','name',_0xdcb6('0x23'),_0xdcb6('0x4d'),_0xdcb6('0x4e'),'internal',_0xdcb6('0x4f'),_0xdcb6('0x24')]})[_0xdcb6('0x17')](function(_0xf29023){if(_0xf29023){_0x1b9e9c=_0xf29023;_0x2eeac1=_0x3fe5fc[_0xdcb6('0x31')][_0xdcb6('0x24')]?_0x3fe5fc[_0xdcb6('0x31')][_0xdcb6('0x24')]:util['format'](_0xdcb6('0x30'),_0x1b9e9c[_0xdcb6('0x22')]);return db[_0xdcb6('0xe')]['count']({'where':{'role':_0xdcb6('0x50'),'online':!![],'id':{'$ne':_0x1b9e9c['id']}}});}})[_0xdcb6('0x17')](function(_0x314ac2){if(_0x314ac2){_0x3f86c8=_0x314ac2;return require('../../config/license/util')[_0xdcb6('0x51')]();}})[_0xdcb6('0x17')](function(_0x4d8ef8){if(_0x4d8ef8&&_0x4d8ef8[_0xdcb6('0x52')]&&_0x3f86c8>=_0x4d8ef8[_0xdcb6('0x52')]){throw new Error('Maximum\x20login\x20has\x20been\x20reached');}})[_0xdcb6('0x17')](function(){if(_0x1b9e9c){return db[_0xdcb6('0x25')][_0xdcb6('0x49')]({'where':{'membername':_0x1b9e9c[_0xdcb6('0x22')]},'individualHooks':!![]});}})['then'](function(){if(_0x1b9e9c){return _0x1b9e9c[_0xdcb6('0x53')]({'raw':!![]});}})[_0xdcb6('0x17')](function(_0x55e1dc){if(_0x1b9e9c){if(_0x55e1dc){var _0x5287bf=[];_0x13f1a4=_0x55e1dc;if(_0x13f1a4['length']){for(var _0x2718cc=0x0;_0x2718cc<_0x13f1a4[_0xdcb6('0x2b')];_0x2718cc++){_0x5287bf[_0xdcb6('0x4a')](db['UserVoiceQueueRt']['upsert']({'membername':_0x1b9e9c['name'],'UserId':_0x1b9e9c['id'],'queue_name':_0x13f1a4[_0x2718cc][_0xdcb6('0x22')],'VoiceQueueId':_0x13f1a4[_0x2718cc]['id'],'interface':_0x2eeac1,'paused':_0x1b9e9c[_0xdcb6('0x4f')]||![],'penalty':_0x13f1a4[_0x2718cc][_0xdcb6('0x54')]||0x0}));}return BPromise[_0xdcb6('0x4b')](_0x5287bf);}}}})[_0xdcb6('0x17')](function(){if(_0x1b9e9c){return db[_0xdcb6('0x27')][_0xdcb6('0xf')]({'where':{'membername':_0x1b9e9c[_0xdcb6('0x22')],'exitAt':null}});}})[_0xdcb6('0x17')](function(_0x22829a){if(_0x1b9e9c){if(_0x22829a&&_0x22829a[_0xdcb6('0x2b')]){var _0xcccbfc=[];_0x22829a[_0xdcb6('0x2e')](function(_0x3d274a){_0xcccbfc['push'](_0x3d274a[_0xdcb6('0x26')]({'exitAt':moment()[_0xdcb6('0x29')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0xdcb6('0x4b')](_0xcccbfc);}}})[_0xdcb6('0x17')](function(){if(_0x1b9e9c){var _0x198145=[];var _0x70a78=[];var _0x52309c=utils[_0xdcb6('0x2d')]();var _0x26ffdf={'membername':_0x1b9e9c[_0xdcb6('0x22')],'interface':_0x2eeac1,'enterAt':moment()['format'](_0xdcb6('0x2a')),'role':_0x1b9e9c[_0xdcb6('0x23')],'internal':_0x1b9e9c[_0xdcb6('0x32')]};_0x52309c[_0xdcb6('0x2e')](function(_0x1b9c16){_0x198145[_0xdcb6('0x4a')](_[_0xdcb6('0x55')]({'channel':_0x1b9c16,'type':'LOGIN','data1':'callysquare','data2':_0x2eeac1},_0x26ffdf));if(_0x1b9e9c['loginInPause']){_0x70a78['push'](_[_0xdcb6('0x55')]({'channel':_0x1b9c16,'type':_0xdcb6('0x28'),'data1':_0xdcb6('0x56')},_0x26ffdf));}});return db[_0xdcb6('0x27')][_0xdcb6('0x57')](_0x198145[_0xdcb6('0x58')](_0x70a78),{'individualHooks':!![]});}})['then'](function(){if(_0x1b9e9c){return _0x1b9e9c[_0xdcb6('0x26')]({'online':!![],'lastLoginAt':moment()[_0xdcb6('0x29')](_0xdcb6('0x2a')),'voicePause':_0x1b9e9c['loginInPause']||![],'mailPause':_0x1b9e9c['loginInPause']||![],'chatPause':_0x1b9e9c[_0xdcb6('0x4f')]||![],'faxPause':_0x1b9e9c[_0xdcb6('0x4f')]||![],'smsPause':_0x1b9e9c[_0xdcb6('0x4f')]||![],'openchannelPause':_0x1b9e9c['loginInPause']||![],'pauseType':_0x1b9e9c[_0xdcb6('0x4f')]?_0xdcb6('0x56'):null,'lastPauseAt':moment()[_0xdcb6('0x29')](_0xdcb6('0x2a')),'interface':_0x2eeac1});}})['then'](function(_0x45c828){_0x245f36(_0x45c828);})[_0xdcb6('0x1f')](function(_0x4b071c){_0x454e4b(_0x3c7a67['error'](0x1f4,_0x4b071c['message']));});});};
\ No newline at end of file