Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / user / user.rpc.js
index 4a4eeea..a0e8694 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x57c0=['UserVoiceQueueRt','update','findAll','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','getChannels','forEach','push','isNil','SIP/%s','body','internal','uniqueid','MemberReport','bulkCreate','UnpauseUser','name','channel','isValidChannel','Unknown\x20channel','voice','system','mail','fax','PAUSE','set','%s%s','Pause','LogoutUser','findOne','destroy','all','mobile','phone','count','agent','../../config/license/util','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','upsert','loginInPause','merge','LOGIN','callysquare','concat','LOGININPAUSE','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./user.socket','register','request','then','User,\x20%s,\x20%s','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','User','options','raw','attributes','include','map','model','info','GetUser','ShowUser','find','where','PauseUser','role','interface'];(function(_0x47e7cb,_0x4c1b8d){var _0x2a8874=function(_0x36498f){while(--_0x36498f){_0x47e7cb['push'](_0x47e7cb['shift']());}};_0x2a8874(++_0x4c1b8d);}(_0x57c0,0x1a5));var _0x057c=function(_0x3037c0,_0x5de2fe){_0x3037c0=_0x3037c0-0x0;var _0x59802e=_0x57c0[_0x3037c0];return _0x59802e;};'use strict';var _=require(_0x057c('0x0'));var util=require(_0x057c('0x1'));var moment=require(_0x057c('0x2'));var BPromise=require(_0x057c('0x3'));var rs=require(_0x057c('0x4'));var fs=require('fs');var Redis=require(_0x057c('0x5'));var db=require(_0x057c('0x6'))['db'];var utils=require(_0x057c('0x7'));var logger=require(_0x057c('0x8'))('rpc');var config=require('../../config/environment');var jayson=require(_0x057c('0x9'));var client=jayson[_0x057c('0xa')][_0x057c('0xb')]({'port':0x232a});config[_0x057c('0xc')]=_[_0x057c('0xd')](config[_0x057c('0xc')],{'host':_0x057c('0xe'),'port':0x18eb});var socket=require(_0x057c('0xf'))(new Redis(config[_0x057c('0xc')]));require(_0x057c('0x10'))[_0x057c('0x11')](socket);function respondWithRpcPromise(_0x47e915,_0x5c6369,_0x39a12b){return new BPromise(function(_0x1687ca,_0x406c07){return client[_0x057c('0x12')](_0x47e915,_0x39a12b)[_0x057c('0x13')](function(_0x1ef2f8){logger['info'](_0x057c('0x14'),_0x5c6369,_0x057c('0x15'));logger[_0x057c('0x16')](_0x057c('0x17'),_0x5c6369,_0x057c('0x15'),JSON[_0x057c('0x18')](_0x1ef2f8));if(_0x1ef2f8[_0x057c('0x19')]){if(_0x1ef2f8['error']['code']===0x1f4){logger[_0x057c('0x19')](_0x057c('0x14'),_0x5c6369,_0x1ef2f8[_0x057c('0x19')][_0x057c('0x1a')]);return _0x406c07(_0x1ef2f8[_0x057c('0x19')][_0x057c('0x1a')]);}logger['error'](_0x057c('0x14'),_0x5c6369,_0x1ef2f8[_0x057c('0x19')][_0x057c('0x1a')]);return _0x1687ca(_0x1ef2f8[_0x057c('0x19')][_0x057c('0x1a')]);}else{logger['info'](_0x057c('0x14'),_0x5c6369,_0x057c('0x15'));_0x1687ca(_0x1ef2f8[_0x057c('0x1b')][_0x057c('0x1a')]);}})[_0x057c('0x1c')](function(_0x4850ef){logger[_0x057c('0x19')](_0x057c('0x14'),_0x5c6369,_0x4850ef);_0x406c07(_0x4850ef);});});}exports['GetUser']=function(_0x19efb4){var _0x310ca8=this;return new Promise(function(_0x396df6,_0x202c86){return db[_0x057c('0x1d')]['findAll']({'raw':_0x19efb4[_0x057c('0x1e')]?_0x19efb4[_0x057c('0x1e')][_0x057c('0x1f')]===undefined?!![]:![]:!![],'where':_0x19efb4[_0x057c('0x1e')]?_0x19efb4[_0x057c('0x1e')]['where']||null:null,'attributes':_0x19efb4['options']?_0x19efb4[_0x057c('0x1e')][_0x057c('0x20')]||null:null,'limit':_0x19efb4[_0x057c('0x1e')]?_0x19efb4[_0x057c('0x1e')]['limit']||null:null,'include':_0x19efb4['options']?_0x19efb4['options'][_0x057c('0x21')]?_[_0x057c('0x22')](_0x19efb4[_0x057c('0x1e')][_0x057c('0x21')],function(_0x694fce){return{'model':db[_0x694fce[_0x057c('0x23')]],'as':_0x694fce['as'],'attributes':_0x694fce[_0x057c('0x20')],'include':_0x694fce['include']?_['map'](_0x694fce[_0x057c('0x21')],function(_0x2c3c33){return{'model':db[_0x2c3c33[_0x057c('0x23')]],'as':_0x2c3c33['as'],'attributes':_0x2c3c33[_0x057c('0x20')],'include':_0x2c3c33[_0x057c('0x21')]?_[_0x057c('0x22')](_0x2c3c33[_0x057c('0x21')],function(_0xa2192a){return{'model':db[_0xa2192a[_0x057c('0x23')]],'as':_0xa2192a['as'],'attributes':_0xa2192a['attributes']};}):[]};}):[]};}):[]:[]})[_0x057c('0x13')](function(_0x986781){logger[_0x057c('0x24')](_0x057c('0x25'),_0x19efb4);logger['debug']('GetUser',_0x19efb4,JSON[_0x057c('0x18')](_0x986781));_0x396df6(_0x986781);})[_0x057c('0x1c')](function(_0xad3e25){logger[_0x057c('0x19')](_0x057c('0x25'),_0xad3e25[_0x057c('0x1a')],_0x19efb4);_0x202c86(_0x310ca8[_0x057c('0x19')](0x1f4,_0xad3e25[_0x057c('0x1a')]));});});};exports[_0x057c('0x26')]=function(_0x25439c){var _0x2a18b5=this;return new Promise(function(_0x3bac27,_0x1950bc){return db[_0x057c('0x1d')][_0x057c('0x27')]({'raw':_0x25439c[_0x057c('0x1e')]?_0x25439c[_0x057c('0x1e')][_0x057c('0x1f')]===undefined?!![]:![]:!![],'where':_0x25439c[_0x057c('0x1e')]?_0x25439c[_0x057c('0x1e')][_0x057c('0x28')]||null:null,'attributes':_0x25439c[_0x057c('0x1e')]?_0x25439c['options']['attributes']||null:null,'include':_0x25439c['options']?_0x25439c[_0x057c('0x1e')][_0x057c('0x21')]?_[_0x057c('0x22')](_0x25439c[_0x057c('0x1e')]['include'],function(_0x9dc9b7){return{'model':db[_0x9dc9b7[_0x057c('0x23')]],'as':_0x9dc9b7['as'],'attributes':_0x9dc9b7[_0x057c('0x20')],'include':_0x9dc9b7[_0x057c('0x21')]?_[_0x057c('0x22')](_0x9dc9b7['include'],function(_0x1fbad3){return{'model':db[_0x1fbad3[_0x057c('0x23')]],'as':_0x1fbad3['as'],'attributes':_0x1fbad3[_0x057c('0x20')],'include':_0x1fbad3[_0x057c('0x21')]?_[_0x057c('0x22')](_0x1fbad3[_0x057c('0x21')],function(_0xd7649b){return{'model':db[_0xd7649b[_0x057c('0x23')]],'as':_0xd7649b['as'],'attributes':_0xd7649b[_0x057c('0x20')]};}):[]};}):[]};}):[]:[]})[_0x057c('0x13')](function(_0x3662a8){logger[_0x057c('0x24')](_0x057c('0x26'),_0x25439c);logger[_0x057c('0x16')](_0x057c('0x26'),_0x25439c,JSON[_0x057c('0x18')](_0x3662a8));_0x3bac27(_0x3662a8);})['catch'](function(_0x25b82d){logger[_0x057c('0x19')](_0x057c('0x26'),_0x25b82d[_0x057c('0x1a')],_0x25439c);_0x1950bc(_0x2a18b5['error'](0x1f4,_0x25b82d['message']));});});};exports[_0x057c('0x29')]=function(_0x49807d){var _0x4429f4=this;return new Promise(function(_0x2aa4c6,_0x79edf1){var _0x581402;return db[_0x057c('0x1d')]['find']({'where':_0x49807d[_0x057c('0x1e')][_0x057c('0x28')]||{},'attributes':['id','name',_0x057c('0x2a'),'internal',_0x057c('0x2b')]})['then'](function(_0xb4257d){if(_0xb4257d){_0x581402=_0xb4257d;return db[_0x057c('0x2c')][_0x057c('0x2d')]({'paused':0x1},{'where':{'UserId':_0x581402['id']},'individualHooks':!![]});}})[_0x057c('0x13')](function(){if(_0x581402){return db['MemberReport'][_0x057c('0x2e')]({'where':{'membername':_0x581402['name'],'type':'PAUSE','exitAt':null}});}})[_0x057c('0x13')](function(_0x55fdf0){if(_0x581402){if(_0x55fdf0&&_0x55fdf0[_0x057c('0x2f')]){var _0x36281f=moment()[_0x057c('0x30')](_0x057c('0x31'));for(var _0x55d3f8=0x0,_0x4f33f7=_0x55fdf0[_0x057c('0x2f')];_0x55d3f8<_0x4f33f7;_0x55d3f8++){_0x55fdf0[_0x55d3f8][_0x057c('0x32')]({'exitAt':_0x36281f});}}}})[_0x057c('0x13')](function(){if(_0x581402){var _0x15dad9=[];var _0x5b675d=utils[_0x057c('0x33')]();_0x5b675d[_0x057c('0x34')](function(_0x1921ca){_0x15dad9[_0x057c('0x35')]({'channel':_0x1921ca,'membername':_0x581402['name'],'interface':_[_0x057c('0x36')](_0x581402[_0x057c('0x2b')])?util[_0x057c('0x30')](_0x057c('0x37'),_0x581402['name']):_0x581402['interface'],'type':'PAUSE','enterAt':moment()[_0x057c('0x30')](_0x057c('0x31')),'data1':_0x49807d[_0x057c('0x38')]['type']||'DEFAULT\x20PAUSE','role':_0x581402[_0x057c('0x2a')],'internal':_0x581402[_0x057c('0x39')],'uniqueid':_0x49807d[_0x057c('0x38')][_0x057c('0x3a')]||null});});return db[_0x057c('0x3b')][_0x057c('0x3c')](_0x15dad9,{'individualHooks':!![]});}})[_0x057c('0x13')](function(){if(_0x581402){return _0x581402['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'pauseType':_0x49807d['body']['type']||'DEFAULT\x20PAUSE','lastPauseAt':moment()[_0x057c('0x30')]('YYYY-MM-DD\x20HH:mm:ss')});}})[_0x057c('0x13')](function(_0xda0984){_0x2aa4c6(_0xda0984);})[_0x057c('0x1c')](function(_0x1436cc){_0x79edf1(_0x4429f4['error'](0x1f4,_0x1436cc['message']));});});};exports[_0x057c('0x3d')]=function(_0x5afa74){var _0x1e1f4e=this;return new Promise(function(_0x243422,_0x2184dc){var _0x42763a;return db[_0x057c('0x1d')]['findOne']({'where':_0x5afa74[_0x057c('0x1e')]['where']||{},'attributes':['id',_0x057c('0x3e')]})[_0x057c('0x13')](function(_0x285a8f){if(_0x285a8f){_0x42763a=_0x285a8f;if(_0x5afa74[_0x057c('0x38')][_0x057c('0x3f')]&&!utils[_0x057c('0x40')](_0x5afa74['body']['channel'])){throw new Error(_0x057c('0x41'));}switch(_0x5afa74[_0x057c('0x38')][_0x057c('0x3f')]){case _0x057c('0x42'):return db[_0x057c('0x2c')][_0x057c('0x2d')]({'paused':0x0},{'where':{'UserId':_0x42763a['id']}})['then'](function(){return db[_0x057c('0x3b')]['find']({'where':{'channel':_0x5afa74['body'][_0x057c('0x3f')],'membername':_0x42763a[_0x057c('0x3e')],'type':'PAUSE','exitAt':null}});})[_0x057c('0x13')](function(_0x972e32){if(_0x972e32){return _0x972e32[_0x057c('0x2d')]({'exitAt':moment()[_0x057c('0x30')](_0x057c('0x31')),'data2':_0x057c('0x43')},{'individualHooks':!![]});}return null;})[_0x057c('0x13')](function(){return _0x42763a['update']({'voicePause':![]});});case _0x057c('0x44'):case'chat':case _0x057c('0x45'):case'sms':case'openchannel':return db[_0x057c('0x3b')][_0x057c('0x27')]({'where':{'channel':_0x5afa74[_0x057c('0x38')]['channel'],'membername':_0x42763a[_0x057c('0x3e')],'type':_0x057c('0x46'),'exitAt':null}})[_0x057c('0x13')](function(_0x4c3ae0){return _0x4c3ae0[_0x057c('0x2d')]({'exitAt':moment()[_0x057c('0x30')](_0x057c('0x31')),'data2':'system'},{'individualHooks':!![]});})[_0x057c('0x13')](function(){var _0x40c109={};_[_0x057c('0x47')](_0x40c109,util['format'](_0x057c('0x48'),_0x5afa74[_0x057c('0x38')][_0x057c('0x3f')],_0x057c('0x49')),![]);return _0x42763a['update'](_0x40c109);});default:return db[_0x057c('0x2c')][_0x057c('0x2d')]({'paused':0x0},{'where':{'UserId':_0x42763a['id']}})['then'](function(){return db['MemberReport'][_0x057c('0x2e')]({'where':{'membername':_0x42763a[_0x057c('0x3e')],'type':'PAUSE','exitAt':null}});})[_0x057c('0x13')](function(_0x8336a0){var _0x5a6d9e=[];_0x8336a0[_0x057c('0x34')](function(_0x19cdef){_0x5a6d9e[_0x057c('0x35')](_0x19cdef['update']({'exitAt':moment()[_0x057c('0x30')]('YYYY-MM-DD\x20HH:mm:ss'),'data2':_0x057c('0x43')}));});return BPromise['all'](_0x5a6d9e);})[_0x057c('0x13')](function(){return _0x42763a[_0x057c('0x2d')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});});}}})[_0x057c('0x13')](function(_0x3dfc19){_0x243422(_0x3dfc19);})['catch'](function(_0x1cc4d7){_0x2184dc(_0x1e1f4e['error'](0x1f4,_0x1cc4d7[_0x057c('0x1a')]));});});};exports[_0x057c('0x4a')]=function(_0x50a734){var _0x53ea57=this;return new Promise(function(_0x302705,_0x1395fc){var _0x4a59a3;return db['User'][_0x057c('0x4b')]({'where':_0x50a734[_0x057c('0x1e')]['where']||{},'attributes':['id','name']})['then'](function(_0x8d2d9a){if(_0x8d2d9a){_0x4a59a3=_0x8d2d9a;return db[_0x057c('0x2c')][_0x057c('0x4c')]({'where':{'membername':_0x4a59a3[_0x057c('0x3e')]},'individualHooks':!![]});}})[_0x057c('0x13')](function(){if(_0x4a59a3){return db[_0x057c('0x3b')][_0x057c('0x2e')]({'where':{'membername':_0x4a59a3[_0x057c('0x3e')],'exitAt':null}});}})[_0x057c('0x13')](function(_0x1bf6fb){if(_0x4a59a3){if(_0x1bf6fb&&_0x1bf6fb['length']){var _0x7acfb3=[];_0x1bf6fb[_0x057c('0x34')](function(_0x1531e7){_0x7acfb3[_0x057c('0x35')](_0x1531e7['update']({'exitAt':moment()[_0x057c('0x30')](_0x057c('0x31'))}));});return BPromise[_0x057c('0x4d')](_0x7acfb3);}}})[_0x057c('0x13')](function(){if(_0x4a59a3){return _0x4a59a3[_0x057c('0x2d')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})['then'](function(_0x180043){_0x302705(_0x180043);})[_0x057c('0x1c')](function(_0x6dc710){_0x1395fc(_0x53ea57['error'](0x1f4,_0x6dc710[_0x057c('0x1a')]));});});};exports['LoginUser']=function(_0x2a1c9b){var _0x325465=this;return new Promise(function(_0x4654fd,_0x2e739d){var _0x1e37a3;var _0xe549ca;var _0x48424f;var _0x57d791;return db['User'][_0x057c('0x4b')]({'where':_0x2a1c9b[_0x057c('0x1e')]['where']||{},'attributes':['id',_0x057c('0x3e'),_0x057c('0x2a'),_0x057c('0x4e'),_0x057c('0x4f'),_0x057c('0x39'),'loginInPause',_0x057c('0x2b')]})['then'](function(_0x5e03cb){if(_0x5e03cb){_0x1e37a3=_0x5e03cb;_0x57d791=_0x2a1c9b[_0x057c('0x38')]['interface']?_0x2a1c9b['body'][_0x057c('0x2b')]:util['format']('SIP/%s',_0x1e37a3['name']);return db[_0x057c('0x1d')][_0x057c('0x50')]({'where':{'role':_0x057c('0x51'),'online':!![],'id':{'$ne':_0x1e37a3['id']}}});}})[_0x057c('0x13')](function(_0x511fe4){if(_0x511fe4){_0x48424f=_0x511fe4;return require(_0x057c('0x52'))[_0x057c('0x53')]();}})[_0x057c('0x13')](function(_0x360846){if(_0x360846&&_0x360846[_0x057c('0x54')]&&_0x48424f>=_0x360846[_0x057c('0x54')]){throw new Error(_0x057c('0x55'));}})[_0x057c('0x13')](function(){if(_0x1e37a3){return db['UserVoiceQueueRt'][_0x057c('0x4c')]({'where':{'membername':_0x1e37a3[_0x057c('0x3e')]},'individualHooks':!![]});}})[_0x057c('0x13')](function(){if(_0x1e37a3){return _0x1e37a3['getVoiceQueues']({'raw':!![]});}})[_0x057c('0x13')](function(_0x59f241){if(_0x1e37a3){if(_0x59f241){var _0x17e8cd=[];_0xe549ca=_0x59f241;if(_0xe549ca[_0x057c('0x2f')]){for(var _0x2bf100=0x0;_0x2bf100<_0xe549ca[_0x057c('0x2f')];_0x2bf100++){_0x17e8cd[_0x057c('0x35')](db[_0x057c('0x2c')][_0x057c('0x56')]({'membername':_0x1e37a3[_0x057c('0x3e')],'UserId':_0x1e37a3['id'],'queue_name':_0xe549ca[_0x2bf100][_0x057c('0x3e')],'VoiceQueueId':_0xe549ca[_0x2bf100]['id'],'interface':_0x57d791,'paused':_0x1e37a3[_0x057c('0x57')]||![],'penalty':_0xe549ca[_0x2bf100]['UserVoiceQueue.penalty']||0x0}));}return BPromise['all'](_0x17e8cd);}}}})['then'](function(){if(_0x1e37a3){return db['MemberReport']['findAll']({'where':{'membername':_0x1e37a3[_0x057c('0x3e')],'exitAt':null}});}})[_0x057c('0x13')](function(_0x4c0106){if(_0x1e37a3){if(_0x4c0106&&_0x4c0106[_0x057c('0x2f')]){var _0x337862=[];_0x4c0106['forEach'](function(_0x2bbb34){_0x337862[_0x057c('0x35')](_0x2bbb34[_0x057c('0x2d')]({'exitAt':moment()['format'](_0x057c('0x31'))}));});return BPromise[_0x057c('0x4d')](_0x337862);}}})[_0x057c('0x13')](function(_0x4a88e7){if(_0x1e37a3){var _0xfaa86=[];var _0x2219f4=[];var _0x1272dd=utils[_0x057c('0x33')]();var _0x195ff9={'membername':_0x1e37a3[_0x057c('0x3e')],'interface':_0x57d791,'enterAt':moment()[_0x057c('0x30')]('YYYY-MM-DD\x20HH:mm:ss'),'role':_0x1e37a3[_0x057c('0x2a')],'internal':_0x1e37a3[_0x057c('0x39')]};_0x1272dd[_0x057c('0x34')](function(_0x50efc3){_0xfaa86[_0x057c('0x35')](_[_0x057c('0x58')]({'channel':_0x50efc3,'type':_0x057c('0x59'),'data1':_0x057c('0x5a'),'data2':_0x57d791},_0x195ff9));if(_0x1e37a3['loginInPause']){_0x2219f4['push'](_['merge']({'channel':_0x50efc3,'type':_0x057c('0x46'),'data1':'LOGININPAUSE'},_0x195ff9));}});return db[_0x057c('0x3b')][_0x057c('0x3c')](_0xfaa86[_0x057c('0x5b')](_0x2219f4),{'individualHooks':!![]});}})[_0x057c('0x13')](function(){if(_0x1e37a3){return _0x1e37a3[_0x057c('0x2d')]({'online':!![],'lastLoginAt':moment()[_0x057c('0x30')](_0x057c('0x31')),'voicePause':_0x1e37a3['loginInPause']||![],'mailPause':_0x1e37a3[_0x057c('0x57')]||![],'chatPause':_0x1e37a3[_0x057c('0x57')]||![],'faxPause':_0x1e37a3[_0x057c('0x57')]||![],'smsPause':_0x1e37a3[_0x057c('0x57')]||![],'openchannelPause':_0x1e37a3[_0x057c('0x57')]||![],'pauseType':_0x1e37a3['loginInPause']?_0x057c('0x5c'):null,'lastPauseAt':moment()[_0x057c('0x30')](_0x057c('0x31')),'interface':_0x57d791});}})[_0x057c('0x13')](function(_0x2db8b0){_0x4654fd(_0x2db8b0);})[_0x057c('0x1c')](function(_0x322780){_0x2e739d(_0x325465['error'](0x1f4,_0x322780[_0x057c('0x1a')]));});});};
\ 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