Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / api / user / user.rpc.js
index 06d051f..1886fef 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7382=['client','http','redis','localhost','socket.io-emitter','./user.socket','info','User,\x20%s,\x20%s','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetUser','findAll','options','raw','attributes','include','map','model','then','ShowUser','User','find','where','PauseUser','name','internal','interface','UserVoiceQueueRt','MemberReport','PAUSE','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','getChannels','forEach','push','isNil','DEFAULT\x20PAUSE','role','update','body','UnpauseUser','findOne','channel','Unknown\x20channel','system','chat','fax','openchannel','whatsapp','set','%s%s','Pause','destroy','phone','loginInPause','SIP/%s','count','../../config/license/util','agents','Maximum\x20login\x20has\x20been\x20reached','upsert','UserVoiceQueue.penalty','all','merge','LOGIN','callysquare','LOGININPAUSE','bulkCreate','concat','util','randomstring','../../mysqldb','../../config/logger','rpc','jayson/promise'];(function(_0x527220,_0x3ac85d){var _0x51b173=function(_0x50a63c){while(--_0x50a63c){_0x527220['push'](_0x527220['shift']());}};_0x51b173(++_0x3ac85d);}(_0x7382,0x1f2));var _0x2738=function(_0xc2fe40,_0x5d35de){_0xc2fe40=_0xc2fe40-0x0;var _0x249260=_0x7382[_0xc2fe40];return _0x249260;};'use strict';var _=require('lodash');var util=require(_0x2738('0x0'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x2738('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x2738('0x2'))['db'];var utils=require('../../config/utils');var logger=require(_0x2738('0x3'))(_0x2738('0x4'));var config=require('../../config/environment');var jayson=require(_0x2738('0x5'));var client=jayson[_0x2738('0x6')][_0x2738('0x7')]({'port':0x232a});config[_0x2738('0x8')]=_['defaults'](config[_0x2738('0x8')],{'host':_0x2738('0x9'),'port':0x18eb});var socket=require(_0x2738('0xa'))(new Redis(config[_0x2738('0x8')]));require(_0x2738('0xb'))['register'](socket);function respondWithRpcPromise(_0x2eb46d,_0xcd5079,_0x2322cd){return new BPromise(function(_0x23db73,_0x53111a){return client['request'](_0x2eb46d,_0x2322cd)['then'](function(_0x4e1692){logger[_0x2738('0xc')](_0x2738('0xd'),_0xcd5079,_0x2738('0xe'));logger[_0x2738('0xf')](_0x2738('0x10'),_0xcd5079,_0x2738('0xe'),JSON[_0x2738('0x11')](_0x4e1692));if(_0x4e1692[_0x2738('0x12')]){if(_0x4e1692[_0x2738('0x12')][_0x2738('0x13')]===0x1f4){logger[_0x2738('0x12')](_0x2738('0xd'),_0xcd5079,_0x4e1692['error'][_0x2738('0x14')]);return _0x53111a(_0x4e1692[_0x2738('0x12')]['message']);}logger['error'](_0x2738('0xd'),_0xcd5079,_0x4e1692[_0x2738('0x12')][_0x2738('0x14')]);return _0x23db73(_0x4e1692['error'][_0x2738('0x14')]);}else{logger[_0x2738('0xc')](_0x2738('0xd'),_0xcd5079,_0x2738('0xe'));_0x23db73(_0x4e1692[_0x2738('0x15')]['message']);}})[_0x2738('0x16')](function(_0xc512f9){logger[_0x2738('0x12')](_0x2738('0xd'),_0xcd5079,_0xc512f9);_0x53111a(_0xc512f9);});});}exports[_0x2738('0x17')]=function(_0x1e2602){var _0x21eaa7=this;return new Promise(function(_0x23a535,_0x2dcc5e){return db['User'][_0x2738('0x18')]({'raw':_0x1e2602['options']?_0x1e2602[_0x2738('0x19')][_0x2738('0x1a')]===undefined?!![]:![]:!![],'where':_0x1e2602[_0x2738('0x19')]?_0x1e2602[_0x2738('0x19')]['where']||null:null,'attributes':_0x1e2602['options']?_0x1e2602[_0x2738('0x19')][_0x2738('0x1b')]||null:null,'limit':_0x1e2602[_0x2738('0x19')]?_0x1e2602[_0x2738('0x19')]['limit']||null:null,'include':_0x1e2602[_0x2738('0x19')]?_0x1e2602[_0x2738('0x19')][_0x2738('0x1c')]?_[_0x2738('0x1d')](_0x1e2602['options']['include'],function(_0x5b7fd0){return{'model':db[_0x5b7fd0[_0x2738('0x1e')]],'as':_0x5b7fd0['as'],'attributes':_0x5b7fd0[_0x2738('0x1b')],'include':_0x5b7fd0['include']?_[_0x2738('0x1d')](_0x5b7fd0[_0x2738('0x1c')],function(_0x1993c7){return{'model':db[_0x1993c7['model']],'as':_0x1993c7['as'],'attributes':_0x1993c7[_0x2738('0x1b')],'include':_0x1993c7[_0x2738('0x1c')]?_[_0x2738('0x1d')](_0x1993c7[_0x2738('0x1c')],function(_0xbfa426){return{'model':db[_0xbfa426[_0x2738('0x1e')]],'as':_0xbfa426['as'],'attributes':_0xbfa426[_0x2738('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x2738('0x1f')](function(_0x39b7c0){logger['info']('GetUser',_0x1e2602);logger[_0x2738('0xf')](_0x2738('0x17'),_0x1e2602,JSON['stringify'](_0x39b7c0));_0x23a535(_0x39b7c0);})['catch'](function(_0xc1b1e7){logger[_0x2738('0x12')](_0x2738('0x17'),_0xc1b1e7[_0x2738('0x14')],_0x1e2602);_0x2dcc5e(_0x21eaa7[_0x2738('0x12')](0x1f4,_0xc1b1e7[_0x2738('0x14')]));});});};exports[_0x2738('0x20')]=function(_0x4d800d){var _0x1304f4=this;return new Promise(function(_0x5de253,_0x52e996){return db[_0x2738('0x21')][_0x2738('0x22')]({'raw':_0x4d800d[_0x2738('0x19')]?_0x4d800d[_0x2738('0x19')][_0x2738('0x1a')]===undefined?!![]:![]:!![],'where':_0x4d800d['options']?_0x4d800d[_0x2738('0x19')][_0x2738('0x23')]||null:null,'attributes':_0x4d800d[_0x2738('0x19')]?_0x4d800d[_0x2738('0x19')][_0x2738('0x1b')]||null:null,'include':_0x4d800d[_0x2738('0x19')]?_0x4d800d[_0x2738('0x19')][_0x2738('0x1c')]?_[_0x2738('0x1d')](_0x4d800d[_0x2738('0x19')][_0x2738('0x1c')],function(_0x20e02a){return{'model':db[_0x20e02a[_0x2738('0x1e')]],'as':_0x20e02a['as'],'attributes':_0x20e02a[_0x2738('0x1b')],'include':_0x20e02a[_0x2738('0x1c')]?_[_0x2738('0x1d')](_0x20e02a[_0x2738('0x1c')],function(_0x37e05a){return{'model':db[_0x37e05a[_0x2738('0x1e')]],'as':_0x37e05a['as'],'attributes':_0x37e05a[_0x2738('0x1b')],'include':_0x37e05a[_0x2738('0x1c')]?_[_0x2738('0x1d')](_0x37e05a[_0x2738('0x1c')],function(_0x53084c){return{'model':db[_0x53084c[_0x2738('0x1e')]],'as':_0x53084c['as'],'attributes':_0x53084c[_0x2738('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x2738('0x1f')](function(_0x814bf9){logger[_0x2738('0xc')](_0x2738('0x20'),_0x4d800d);logger[_0x2738('0xf')](_0x2738('0x20'),_0x4d800d,JSON[_0x2738('0x11')](_0x814bf9));_0x5de253(_0x814bf9);})[_0x2738('0x16')](function(_0x4a1338){logger[_0x2738('0x12')]('ShowUser',_0x4a1338[_0x2738('0x14')],_0x4d800d);_0x52e996(_0x1304f4[_0x2738('0x12')](0x1f4,_0x4a1338[_0x2738('0x14')]));});});};exports[_0x2738('0x24')]=function(_0x183760){var _0x249729=this;return new Promise(function(_0x4e02e0,_0x15b2cf){var _0x526e9f;return db[_0x2738('0x21')][_0x2738('0x22')]({'where':_0x183760[_0x2738('0x19')][_0x2738('0x23')]||{},'attributes':['id',_0x2738('0x25'),'role',_0x2738('0x26'),_0x2738('0x27')]})['then'](function(_0x31d16b){if(_0x31d16b){_0x526e9f=_0x31d16b;return db[_0x2738('0x28')]['update']({'paused':0x1},{'where':{'UserId':_0x526e9f['id']},'individualHooks':!![]});}})[_0x2738('0x1f')](function(){if(_0x526e9f){return db[_0x2738('0x29')][_0x2738('0x18')]({'where':{'membername':_0x526e9f[_0x2738('0x25')],'type':_0x2738('0x2a'),'exitAt':null}});}})['then'](function(_0x375740){if(_0x526e9f){if(_0x375740&&_0x375740[_0x2738('0x2b')]){var _0x424098=moment()[_0x2738('0x2c')](_0x2738('0x2d'));for(var _0x34d90a=0x0,_0x53c96f=_0x375740[_0x2738('0x2b')];_0x34d90a<_0x53c96f;_0x34d90a++){_0x375740[_0x34d90a][_0x2738('0x2e')]({'exitAt':_0x424098});}}}})[_0x2738('0x1f')](function(){if(_0x526e9f){var _0x5ce657=[];var _0x2b5dbd=utils[_0x2738('0x2f')]();_0x2b5dbd[_0x2738('0x30')](function(_0x38da0f){_0x5ce657[_0x2738('0x31')]({'channel':_0x38da0f,'membername':_0x526e9f[_0x2738('0x25')],'interface':_[_0x2738('0x32')](_0x526e9f['interface'])?util[_0x2738('0x2c')]('SIP/%s',_0x526e9f[_0x2738('0x25')]):_0x526e9f[_0x2738('0x27')],'type':'PAUSE','enterAt':moment()[_0x2738('0x2c')]('YYYY-MM-DD\x20HH:mm:ss'),'data1':_0x183760['body']['type']||_0x2738('0x33'),'role':_0x526e9f[_0x2738('0x34')],'internal':_0x526e9f[_0x2738('0x26')],'uniqueid':_0x183760['body']['uniqueid']||null});});return db[_0x2738('0x29')]['bulkCreate'](_0x5ce657,{'individualHooks':!![]});}})[_0x2738('0x1f')](function(){if(_0x526e9f){return _0x526e9f[_0x2738('0x35')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x183760[_0x2738('0x36')]['type']||_0x2738('0x33'),'lastPauseAt':moment()[_0x2738('0x2c')](_0x2738('0x2d'))});}})[_0x2738('0x1f')](function(_0x26e12a){_0x4e02e0(_0x26e12a);})[_0x2738('0x16')](function(_0x4a8027){_0x15b2cf(_0x249729[_0x2738('0x12')](0x1f4,_0x4a8027[_0x2738('0x14')]));});});};exports[_0x2738('0x37')]=function(_0x9b1a54){var _0xc01aa2=this;return new Promise(function(_0x23ee02,_0xe1f6de){var _0x1cb770;return db[_0x2738('0x21')][_0x2738('0x38')]({'where':_0x9b1a54['options']['where']||{},'attributes':['id','name']})['then'](function(_0x3580ad){if(_0x3580ad){_0x1cb770=_0x3580ad;if(_0x9b1a54[_0x2738('0x36')][_0x2738('0x39')]&&!utils['isValidChannel'](_0x9b1a54[_0x2738('0x36')][_0x2738('0x39')])){throw new Error(_0x2738('0x3a'));}switch(_0x9b1a54['body']['channel']){case'voice':return db[_0x2738('0x28')][_0x2738('0x35')]({'paused':0x0},{'where':{'UserId':_0x1cb770['id']}})[_0x2738('0x1f')](function(){return db[_0x2738('0x29')][_0x2738('0x22')]({'where':{'channel':_0x9b1a54[_0x2738('0x36')][_0x2738('0x39')],'membername':_0x1cb770[_0x2738('0x25')],'type':_0x2738('0x2a'),'exitAt':null}});})['then'](function(_0x2fc155){if(_0x2fc155){return _0x2fc155[_0x2738('0x35')]({'exitAt':moment()['format'](_0x2738('0x2d')),'data2':_0x2738('0x3b')},{'individualHooks':!![]});}return null;})[_0x2738('0x1f')](function(){return _0x1cb770[_0x2738('0x35')]({'voicePause':![]});});case'mail':case _0x2738('0x3c'):case _0x2738('0x3d'):case'sms':case _0x2738('0x3e'):case _0x2738('0x3f'):return db['MemberReport'][_0x2738('0x22')]({'where':{'channel':_0x9b1a54[_0x2738('0x36')][_0x2738('0x39')],'membername':_0x1cb770[_0x2738('0x25')],'type':_0x2738('0x2a'),'exitAt':null}})[_0x2738('0x1f')](function(_0x32ae05){return _0x32ae05['update']({'exitAt':moment()[_0x2738('0x2c')](_0x2738('0x2d')),'data2':_0x2738('0x3b')},{'individualHooks':!![]});})[_0x2738('0x1f')](function(){var _0x4a49a4={};_[_0x2738('0x40')](_0x4a49a4,util[_0x2738('0x2c')](_0x2738('0x41'),_0x9b1a54[_0x2738('0x36')][_0x2738('0x39')],_0x2738('0x42')),![]);return _0x1cb770[_0x2738('0x35')](_0x4a49a4);});default:return db[_0x2738('0x28')][_0x2738('0x35')]({'paused':0x0},{'where':{'UserId':_0x1cb770['id']}})[_0x2738('0x1f')](function(){return db[_0x2738('0x29')][_0x2738('0x18')]({'where':{'membername':_0x1cb770[_0x2738('0x25')],'type':'PAUSE','exitAt':null}});})[_0x2738('0x1f')](function(_0x4335ca){var _0x5b18ec=[];_0x4335ca[_0x2738('0x30')](function(_0xe07562){_0x5b18ec[_0x2738('0x31')](_0xe07562[_0x2738('0x35')]({'exitAt':moment()[_0x2738('0x2c')](_0x2738('0x2d')),'data2':_0x2738('0x3b')}));});return BPromise['all'](_0x5b18ec);})['then'](function(){return _0x1cb770[_0x2738('0x35')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0x2738('0x1f')](function(_0x78031){_0x23ee02(_0x78031);})[_0x2738('0x16')](function(_0x386282){_0xe1f6de(_0xc01aa2[_0x2738('0x12')](0x1f4,_0x386282[_0x2738('0x14')]));});});};exports['LogoutUser']=function(_0x4f951d){var _0x4194d0=this;return new Promise(function(_0x9e0db1,_0x4c2ea3){var _0x54b4c3;return db[_0x2738('0x21')]['findOne']({'where':_0x4f951d[_0x2738('0x19')][_0x2738('0x23')]||{},'attributes':['id','name']})[_0x2738('0x1f')](function(_0x499584){if(_0x499584){_0x54b4c3=_0x499584;return db[_0x2738('0x28')][_0x2738('0x43')]({'where':{'membername':_0x54b4c3[_0x2738('0x25')]},'individualHooks':!![]});}})[_0x2738('0x1f')](function(){if(_0x54b4c3){return db[_0x2738('0x29')][_0x2738('0x18')]({'where':{'membername':_0x54b4c3[_0x2738('0x25')],'exitAt':null}});}})[_0x2738('0x1f')](function(_0xf2ff29){if(_0x54b4c3){if(_0xf2ff29&&_0xf2ff29[_0x2738('0x2b')]){var _0x4e2e1c=[];_0xf2ff29[_0x2738('0x30')](function(_0x26b3d2){_0x4e2e1c[_0x2738('0x31')](_0x26b3d2['update']({'exitAt':moment()[_0x2738('0x2c')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise['all'](_0x4e2e1c);}}})['then'](function(){if(_0x54b4c3){return _0x54b4c3['update']({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0x2738('0x1f')](function(_0x5f1464){_0x9e0db1(_0x5f1464);})['catch'](function(_0x40678){_0x4c2ea3(_0x4194d0[_0x2738('0x12')](0x1f4,_0x40678['message']));});});};exports['LoginUser']=function(_0x257b5d){var _0x2250ea=this;return new Promise(function(_0x44dd79,_0x28a596){var _0x51151c;var _0x5daca6;var _0x3c0053;var _0x57170a;return db[_0x2738('0x21')][_0x2738('0x38')]({'where':_0x257b5d[_0x2738('0x19')]['where']||{},'attributes':['id','name',_0x2738('0x34'),'mobile',_0x2738('0x44'),_0x2738('0x26'),_0x2738('0x45'),_0x2738('0x27')]})[_0x2738('0x1f')](function(_0x464cca){if(_0x464cca){_0x51151c=_0x464cca;_0x57170a=_0x257b5d[_0x2738('0x36')][_0x2738('0x27')]?_0x257b5d[_0x2738('0x36')][_0x2738('0x27')]:util['format'](_0x2738('0x46'),_0x51151c[_0x2738('0x25')]);return db[_0x2738('0x21')][_0x2738('0x47')]({'where':{'role':'agent','online':!![],'id':{'$ne':_0x51151c['id']}}});}})['then'](function(_0x23a425){if(_0x23a425){_0x3c0053=_0x23a425;return require(_0x2738('0x48'))['getLicense']();}})['then'](function(_0x592929){if(_0x592929&&_0x592929[_0x2738('0x49')]&&_0x3c0053>=_0x592929[_0x2738('0x49')]){throw new Error(_0x2738('0x4a'));}})[_0x2738('0x1f')](function(){if(_0x51151c){return db[_0x2738('0x28')][_0x2738('0x43')]({'where':{'membername':_0x51151c[_0x2738('0x25')]},'individualHooks':!![]});}})['then'](function(){if(_0x51151c){return _0x51151c['getVoiceQueues']({'raw':!![]});}})[_0x2738('0x1f')](function(_0x47a66d){if(_0x51151c){if(_0x47a66d){var _0x2b3786=[];_0x5daca6=_0x47a66d;if(_0x5daca6['length']){for(var _0x545c0f=0x0;_0x545c0f<_0x5daca6[_0x2738('0x2b')];_0x545c0f++){_0x2b3786[_0x2738('0x31')](db[_0x2738('0x28')][_0x2738('0x4b')]({'membername':_0x51151c[_0x2738('0x25')],'UserId':_0x51151c['id'],'queue_name':_0x5daca6[_0x545c0f][_0x2738('0x25')],'VoiceQueueId':_0x5daca6[_0x545c0f]['id'],'interface':_0x57170a,'paused':_0x51151c[_0x2738('0x45')]||![],'penalty':_0x5daca6[_0x545c0f][_0x2738('0x4c')]||0x0}));}return BPromise[_0x2738('0x4d')](_0x2b3786);}}}})[_0x2738('0x1f')](function(){if(_0x51151c){return db[_0x2738('0x29')]['findAll']({'where':{'membername':_0x51151c[_0x2738('0x25')],'exitAt':null}});}})['then'](function(_0x4c1b8f){if(_0x51151c){if(_0x4c1b8f&&_0x4c1b8f[_0x2738('0x2b')]){var _0x404233=[];_0x4c1b8f[_0x2738('0x30')](function(_0x209bcf){_0x404233[_0x2738('0x31')](_0x209bcf[_0x2738('0x35')]({'exitAt':moment()[_0x2738('0x2c')](_0x2738('0x2d'))}));});return BPromise[_0x2738('0x4d')](_0x404233);}}})['then'](function(_0x3a46bd){if(_0x51151c){var _0x1e62b4=[];var _0x5d41b5=[];var _0x4054c5=utils[_0x2738('0x2f')]();var _0x215ecc={'membername':_0x51151c['name'],'interface':_0x57170a,'enterAt':moment()[_0x2738('0x2c')]('YYYY-MM-DD\x20HH:mm:ss'),'role':_0x51151c[_0x2738('0x34')],'internal':_0x51151c[_0x2738('0x26')]};_0x4054c5['forEach'](function(_0x1e362e){_0x1e62b4[_0x2738('0x31')](_[_0x2738('0x4e')]({'channel':_0x1e362e,'type':_0x2738('0x4f'),'data1':_0x2738('0x50'),'data2':_0x57170a},_0x215ecc));if(_0x51151c[_0x2738('0x45')]){_0x5d41b5[_0x2738('0x31')](_[_0x2738('0x4e')]({'channel':_0x1e362e,'type':'PAUSE','data1':_0x2738('0x51')},_0x215ecc));}});return db[_0x2738('0x29')][_0x2738('0x52')](_0x1e62b4[_0x2738('0x53')](_0x5d41b5),{'individualHooks':!![]});}})[_0x2738('0x1f')](function(){if(_0x51151c){return _0x51151c[_0x2738('0x35')]({'online':!![],'lastLoginAt':moment()[_0x2738('0x2c')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x51151c[_0x2738('0x45')]||![],'mailPause':_0x51151c[_0x2738('0x45')]||![],'chatPause':_0x51151c['loginInPause']||![],'faxPause':_0x51151c[_0x2738('0x45')]||![],'smsPause':_0x51151c['loginInPause']||![],'openchannelPause':_0x51151c[_0x2738('0x45')]||![],'pauseType':_0x51151c[_0x2738('0x45')]?_0x2738('0x51'):null,'lastPauseAt':moment()[_0x2738('0x2c')](_0x2738('0x2d')),'interface':_0x57170a});}})['then'](function(_0x373799){_0x44dd79(_0x373799);})['catch'](function(_0x4d86e6){_0x28a596(_0x2250ea[_0x2738('0x12')](0x1f4,_0x4d86e6['message']));});});};
\ No newline at end of file
+var _0x60a5=['length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','forEach','push','isNil','SIP/%s','DEFAULT\x20PAUSE','uniqueid','MemberReport','bulkCreate','body','type','findOne','channel','isValidChannel','Unknown\x20channel','voice','UserVoiceQueueRt','mail','chat','fax','sms','system','set','Pause','all','LogoutUser','destroy','role','mobile','phone','count','agent','getLicense','agents','upsert','loginInPause','UserVoiceQueue.penalty','getChannels','merge','callysquare','concat','lodash','bluebird','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','localhost','socket.io-emitter','redis','./user.socket','then','info','User,\x20%s,\x20%s','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','GetUser','User','findAll','options','raw','where','attributes','limit','map','model','include','catch','ShowUser','PauseUser','find','name','internal','interface','update','PAUSE'];(function(_0x1d5bfd,_0x25075b){var _0xd5b68d=function(_0x15802a){while(--_0x15802a){_0x1d5bfd['push'](_0x1d5bfd['shift']());}};_0xd5b68d(++_0x25075b);}(_0x60a5,0x83));var _0x560a=function(_0x46aff0,_0x122890){_0x46aff0=_0x46aff0-0x0;var _0x9d78cf=_0x60a5[_0x46aff0];return _0x9d78cf;};'use strict';var _=require(_0x560a('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x560a('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x560a('0x2'))['db'];var utils=require(_0x560a('0x3'));var logger=require(_0x560a('0x4'))('rpc');var config=require(_0x560a('0x5'));var jayson=require(_0x560a('0x6'));var client=jayson[_0x560a('0x7')]['http']({'port':0x232a});config['redis']=_['defaults'](config['redis'],{'host':_0x560a('0x8'),'port':0x18eb});var socket=require(_0x560a('0x9'))(new Redis(config[_0x560a('0xa')]));require(_0x560a('0xb'))['register'](socket);function respondWithRpcPromise(_0x4c7a7a,_0x359da4,_0x5d95ee){return new BPromise(function(_0x2e3b88,_0x13c6a3){return client['request'](_0x4c7a7a,_0x5d95ee)[_0x560a('0xc')](function(_0x36e345){logger[_0x560a('0xd')](_0x560a('0xe'),_0x359da4,_0x560a('0xf'));logger[_0x560a('0x10')](_0x560a('0x11'),_0x359da4,_0x560a('0xf'),JSON[_0x560a('0x12')](_0x36e345));if(_0x36e345['error']){if(_0x36e345[_0x560a('0x13')][_0x560a('0x14')]===0x1f4){logger[_0x560a('0x13')]('User,\x20%s,\x20%s',_0x359da4,_0x36e345[_0x560a('0x13')][_0x560a('0x15')]);return _0x13c6a3(_0x36e345[_0x560a('0x13')][_0x560a('0x15')]);}logger['error'](_0x560a('0xe'),_0x359da4,_0x36e345[_0x560a('0x13')][_0x560a('0x15')]);return _0x2e3b88(_0x36e345[_0x560a('0x13')]['message']);}else{logger['info'](_0x560a('0xe'),_0x359da4,_0x560a('0xf'));_0x2e3b88(_0x36e345[_0x560a('0x16')][_0x560a('0x15')]);}})['catch'](function(_0x96deb7){logger[_0x560a('0x13')](_0x560a('0xe'),_0x359da4,_0x96deb7);_0x13c6a3(_0x96deb7);});});}exports[_0x560a('0x17')]=function(_0xe9be04){var _0x4807f2=this;return new Promise(function(_0x32ff83,_0x155c2b){return db[_0x560a('0x18')][_0x560a('0x19')]({'raw':_0xe9be04[_0x560a('0x1a')]?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1b')]===undefined?!![]:![]:!![],'where':_0xe9be04['options']?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1c')]||null:null,'attributes':_0xe9be04[_0x560a('0x1a')]?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1d')]||null:null,'limit':_0xe9be04[_0x560a('0x1a')]?_0xe9be04[_0x560a('0x1a')][_0x560a('0x1e')]||null:null,'include':_0xe9be04['options']?_0xe9be04['options']['include']?_[_0x560a('0x1f')](_0xe9be04[_0x560a('0x1a')]['include'],function(_0x47b251){return{'model':db[_0x47b251[_0x560a('0x20')]],'as':_0x47b251['as'],'attributes':_0x47b251['attributes'],'include':_0x47b251[_0x560a('0x21')]?_[_0x560a('0x1f')](_0x47b251['include'],function(_0x6ad203){return{'model':db[_0x6ad203[_0x560a('0x20')]],'as':_0x6ad203['as'],'attributes':_0x6ad203['attributes'],'include':_0x6ad203[_0x560a('0x21')]?_[_0x560a('0x1f')](_0x6ad203[_0x560a('0x21')],function(_0x305bd9){return{'model':db[_0x305bd9[_0x560a('0x20')]],'as':_0x305bd9['as'],'attributes':_0x305bd9['attributes']};}):[]};}):[]};}):[]:[]})[_0x560a('0xc')](function(_0x3c4af2){logger['info'](_0x560a('0x17'),_0xe9be04);logger[_0x560a('0x10')](_0x560a('0x17'),_0xe9be04,JSON[_0x560a('0x12')](_0x3c4af2));_0x32ff83(_0x3c4af2);})[_0x560a('0x22')](function(_0x226c9c){logger[_0x560a('0x13')]('GetUser',_0x226c9c[_0x560a('0x15')],_0xe9be04);_0x155c2b(_0x4807f2[_0x560a('0x13')](0x1f4,_0x226c9c['message']));});});};exports['ShowUser']=function(_0x16bccd){var _0x465418=this;return new Promise(function(_0x155e3e,_0x546f45){return db['User']['find']({'raw':_0x16bccd['options']?_0x16bccd[_0x560a('0x1a')][_0x560a('0x1b')]===undefined?!![]:![]:!![],'where':_0x16bccd[_0x560a('0x1a')]?_0x16bccd[_0x560a('0x1a')][_0x560a('0x1c')]||null:null,'attributes':_0x16bccd[_0x560a('0x1a')]?_0x16bccd[_0x560a('0x1a')][_0x560a('0x1d')]||null:null,'include':_0x16bccd[_0x560a('0x1a')]?_0x16bccd[_0x560a('0x1a')]['include']?_[_0x560a('0x1f')](_0x16bccd[_0x560a('0x1a')][_0x560a('0x21')],function(_0x2b3c21){return{'model':db[_0x2b3c21[_0x560a('0x20')]],'as':_0x2b3c21['as'],'attributes':_0x2b3c21['attributes'],'include':_0x2b3c21['include']?_[_0x560a('0x1f')](_0x2b3c21[_0x560a('0x21')],function(_0x4388f4){return{'model':db[_0x4388f4[_0x560a('0x20')]],'as':_0x4388f4['as'],'attributes':_0x4388f4[_0x560a('0x1d')],'include':_0x4388f4['include']?_[_0x560a('0x1f')](_0x4388f4[_0x560a('0x21')],function(_0x4c027e){return{'model':db[_0x4c027e[_0x560a('0x20')]],'as':_0x4c027e['as'],'attributes':_0x4c027e[_0x560a('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x560a('0xc')](function(_0x384f39){logger[_0x560a('0xd')](_0x560a('0x23'),_0x16bccd);logger['debug'](_0x560a('0x23'),_0x16bccd,JSON[_0x560a('0x12')](_0x384f39));_0x155e3e(_0x384f39);})[_0x560a('0x22')](function(_0x30fa04){logger['error'](_0x560a('0x23'),_0x30fa04['message'],_0x16bccd);_0x546f45(_0x465418[_0x560a('0x13')](0x1f4,_0x30fa04[_0x560a('0x15')]));});});};exports[_0x560a('0x24')]=function(_0x21b999){var _0x329f01=this;return new Promise(function(_0x8f8f84,_0xc562ac){var _0x2c01c0;return db[_0x560a('0x18')][_0x560a('0x25')]({'where':_0x21b999[_0x560a('0x1a')][_0x560a('0x1c')]||{},'attributes':['id',_0x560a('0x26'),'role',_0x560a('0x27'),_0x560a('0x28')]})[_0x560a('0xc')](function(_0x175719){if(_0x175719){_0x2c01c0=_0x175719;return db['UserVoiceQueueRt'][_0x560a('0x29')]({'paused':0x1},{'where':{'UserId':_0x2c01c0['id']},'individualHooks':!![]});}})['then'](function(){if(_0x2c01c0){return db['MemberReport'][_0x560a('0x19')]({'where':{'membername':_0x2c01c0[_0x560a('0x26')],'type':_0x560a('0x2a'),'exitAt':null}});}})[_0x560a('0xc')](function(_0x1a1d3a){if(_0x2c01c0){if(_0x1a1d3a&&_0x1a1d3a[_0x560a('0x2b')]){var _0x4b245d=moment()[_0x560a('0x2c')](_0x560a('0x2d'));for(var _0x4eb404=0x0,_0x50a2b6=_0x1a1d3a['length'];_0x4eb404<_0x50a2b6;_0x4eb404++){_0x1a1d3a[_0x4eb404][_0x560a('0x2e')]({'exitAt':_0x4b245d});}}}})[_0x560a('0xc')](function(){if(_0x2c01c0){var _0xa7d1a=[];var _0x4813b3=utils['getChannels']();_0x4813b3[_0x560a('0x2f')](function(_0x4e52c3){_0xa7d1a[_0x560a('0x30')]({'channel':_0x4e52c3,'membername':_0x2c01c0[_0x560a('0x26')],'interface':_[_0x560a('0x31')](_0x2c01c0['interface'])?util[_0x560a('0x2c')](_0x560a('0x32'),_0x2c01c0[_0x560a('0x26')]):_0x2c01c0['interface'],'type':_0x560a('0x2a'),'enterAt':moment()[_0x560a('0x2c')](_0x560a('0x2d')),'data1':_0x21b999['body']['type']||_0x560a('0x33'),'role':_0x2c01c0['role'],'internal':_0x2c01c0[_0x560a('0x27')],'uniqueid':_0x21b999['body'][_0x560a('0x34')]||null});});return db[_0x560a('0x35')][_0x560a('0x36')](_0xa7d1a,{'individualHooks':!![]});}})[_0x560a('0xc')](function(){if(_0x2c01c0){return _0x2c01c0[_0x560a('0x29')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x21b999[_0x560a('0x37')][_0x560a('0x38')]||_0x560a('0x33'),'lastPauseAt':moment()['format'](_0x560a('0x2d'))});}})['then'](function(_0x580999){_0x8f8f84(_0x580999);})[_0x560a('0x22')](function(_0xdf1613){_0xc562ac(_0x329f01[_0x560a('0x13')](0x1f4,_0xdf1613[_0x560a('0x15')]));});});};exports['UnpauseUser']=function(_0x563f94){var _0x211111=this;return new Promise(function(_0x5ab3f0,_0x3f8a48){var _0x2146ca;return db['User'][_0x560a('0x39')]({'where':_0x563f94[_0x560a('0x1a')][_0x560a('0x1c')]||{},'attributes':['id',_0x560a('0x26')]})['then'](function(_0x38dae1){if(_0x38dae1){_0x2146ca=_0x38dae1;if(_0x563f94[_0x560a('0x37')][_0x560a('0x3a')]&&!utils[_0x560a('0x3b')](_0x563f94['body'][_0x560a('0x3a')])){throw new Error(_0x560a('0x3c'));}switch(_0x563f94[_0x560a('0x37')][_0x560a('0x3a')]){case _0x560a('0x3d'):return db[_0x560a('0x3e')][_0x560a('0x29')]({'paused':0x0},{'where':{'UserId':_0x2146ca['id']}})[_0x560a('0xc')](function(){return db['MemberReport'][_0x560a('0x25')]({'where':{'channel':_0x563f94[_0x560a('0x37')][_0x560a('0x3a')],'membername':_0x2146ca[_0x560a('0x26')],'type':'PAUSE','exitAt':null}});})[_0x560a('0xc')](function(_0x5eb025){if(_0x5eb025){return _0x5eb025[_0x560a('0x29')]({'exitAt':moment()['format'](_0x560a('0x2d')),'data2':'system'},{'individualHooks':!![]});}return null;})[_0x560a('0xc')](function(){return _0x2146ca[_0x560a('0x29')]({'voicePause':![]});});case _0x560a('0x3f'):case _0x560a('0x40'):case _0x560a('0x41'):case _0x560a('0x42'):case'openchannel':case'whatsapp':return db[_0x560a('0x35')][_0x560a('0x25')]({'where':{'channel':_0x563f94[_0x560a('0x37')][_0x560a('0x3a')],'membername':_0x2146ca[_0x560a('0x26')],'type':_0x560a('0x2a'),'exitAt':null}})[_0x560a('0xc')](function(_0x178f7a){return _0x178f7a[_0x560a('0x29')]({'exitAt':moment()['format'](_0x560a('0x2d')),'data2':_0x560a('0x43')},{'individualHooks':!![]});})['then'](function(){var _0x131744={};_[_0x560a('0x44')](_0x131744,util[_0x560a('0x2c')]('%s%s',_0x563f94[_0x560a('0x37')]['channel'],_0x560a('0x45')),![]);return _0x2146ca[_0x560a('0x29')](_0x131744);});default:return db[_0x560a('0x3e')]['update']({'paused':0x0},{'where':{'UserId':_0x2146ca['id']}})[_0x560a('0xc')](function(){return db[_0x560a('0x35')][_0x560a('0x19')]({'where':{'membername':_0x2146ca[_0x560a('0x26')],'type':'PAUSE','exitAt':null}});})[_0x560a('0xc')](function(_0x6361d5){var _0x234c5b=[];_0x6361d5['forEach'](function(_0x23fdd4){_0x234c5b['push'](_0x23fdd4['update']({'exitAt':moment()['format'](_0x560a('0x2d')),'data2':_0x560a('0x43')}));});return BPromise[_0x560a('0x46')](_0x234c5b);})[_0x560a('0xc')](function(){return _0x2146ca[_0x560a('0x29')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0x560a('0xc')](function(_0x7e602e){_0x5ab3f0(_0x7e602e);})['catch'](function(_0x27384b){_0x3f8a48(_0x211111[_0x560a('0x13')](0x1f4,_0x27384b[_0x560a('0x15')]));});});};exports[_0x560a('0x47')]=function(_0x50c05c){var _0x3e0314=this;return new Promise(function(_0x3e8800,_0x2dfad1){var _0x2ea8b8;return db[_0x560a('0x18')][_0x560a('0x39')]({'where':_0x50c05c[_0x560a('0x1a')]['where']||{},'attributes':['id',_0x560a('0x26')]})['then'](function(_0x3874d2){if(_0x3874d2){_0x2ea8b8=_0x3874d2;return db['UserVoiceQueueRt'][_0x560a('0x48')]({'where':{'membername':_0x2ea8b8[_0x560a('0x26')]},'individualHooks':!![]});}})[_0x560a('0xc')](function(){if(_0x2ea8b8){return db['MemberReport'][_0x560a('0x19')]({'where':{'membername':_0x2ea8b8[_0x560a('0x26')],'exitAt':null}});}})[_0x560a('0xc')](function(_0x1c161a){if(_0x2ea8b8){if(_0x1c161a&&_0x1c161a['length']){var _0x745abe=[];_0x1c161a[_0x560a('0x2f')](function(_0x326a69){_0x745abe[_0x560a('0x30')](_0x326a69[_0x560a('0x29')]({'exitAt':moment()['format'](_0x560a('0x2d'))}));});return BPromise['all'](_0x745abe);}}})[_0x560a('0xc')](function(){if(_0x2ea8b8){return _0x2ea8b8[_0x560a('0x29')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0x560a('0xc')](function(_0x5c6bfe){_0x3e8800(_0x5c6bfe);})[_0x560a('0x22')](function(_0x15a58d){_0x2dfad1(_0x3e0314[_0x560a('0x13')](0x1f4,_0x15a58d[_0x560a('0x15')]));});});};exports['LoginUser']=function(_0x5f305a){var _0x52facf=this;return new Promise(function(_0x5dd836,_0x118cb8){var _0x38feb5;var _0x8c479f;var _0x5075b0;var _0xb992b3;return db[_0x560a('0x18')][_0x560a('0x39')]({'where':_0x5f305a[_0x560a('0x1a')][_0x560a('0x1c')]||{},'attributes':['id',_0x560a('0x26'),_0x560a('0x49'),_0x560a('0x4a'),_0x560a('0x4b'),_0x560a('0x27'),'loginInPause',_0x560a('0x28')]})[_0x560a('0xc')](function(_0x2a1eae){if(_0x2a1eae){_0x38feb5=_0x2a1eae;_0xb992b3=_0x5f305a[_0x560a('0x37')][_0x560a('0x28')]?_0x5f305a[_0x560a('0x37')]['interface']:util['format'](_0x560a('0x32'),_0x38feb5[_0x560a('0x26')]);return db['User'][_0x560a('0x4c')]({'where':{'role':_0x560a('0x4d'),'online':!![],'id':{'$ne':_0x38feb5['id']}}});}})[_0x560a('0xc')](function(_0x1b5d07){if(_0x1b5d07){_0x5075b0=_0x1b5d07;return require('../../config/license/util')[_0x560a('0x4e')]();}})[_0x560a('0xc')](function(_0x3ec18c){if(_0x3ec18c&&_0x3ec18c[_0x560a('0x4f')]&&_0x5075b0>=_0x3ec18c[_0x560a('0x4f')]){throw new Error('Maximum\x20login\x20has\x20been\x20reached');}})[_0x560a('0xc')](function(){if(_0x38feb5){return db[_0x560a('0x3e')][_0x560a('0x48')]({'where':{'membername':_0x38feb5[_0x560a('0x26')]},'individualHooks':!![]});}})[_0x560a('0xc')](function(){if(_0x38feb5){return _0x38feb5['getVoiceQueues']({'raw':!![]});}})[_0x560a('0xc')](function(_0x306546){if(_0x38feb5){if(_0x306546){var _0x1e9d4b=[];_0x8c479f=_0x306546;if(_0x8c479f[_0x560a('0x2b')]){for(var _0x29daba=0x0;_0x29daba<_0x8c479f[_0x560a('0x2b')];_0x29daba++){_0x1e9d4b['push'](db['UserVoiceQueueRt'][_0x560a('0x50')]({'membername':_0x38feb5[_0x560a('0x26')],'UserId':_0x38feb5['id'],'queue_name':_0x8c479f[_0x29daba][_0x560a('0x26')],'VoiceQueueId':_0x8c479f[_0x29daba]['id'],'interface':_0xb992b3,'paused':_0x38feb5[_0x560a('0x51')]||![],'penalty':_0x8c479f[_0x29daba][_0x560a('0x52')]||0x0}));}return BPromise[_0x560a('0x46')](_0x1e9d4b);}}}})[_0x560a('0xc')](function(){if(_0x38feb5){return db[_0x560a('0x35')][_0x560a('0x19')]({'where':{'membername':_0x38feb5['name'],'exitAt':null}});}})['then'](function(_0x402606){if(_0x38feb5){if(_0x402606&&_0x402606[_0x560a('0x2b')]){var _0x16a9ce=[];_0x402606['forEach'](function(_0xbda73e){_0x16a9ce['push'](_0xbda73e[_0x560a('0x29')]({'exitAt':moment()[_0x560a('0x2c')](_0x560a('0x2d'))}));});return BPromise[_0x560a('0x46')](_0x16a9ce);}}})[_0x560a('0xc')](function(_0x198a85){if(_0x38feb5){var _0x16d150=[];var _0x29f194=[];var _0x42ef64=utils[_0x560a('0x53')]();var _0x5ac917={'membername':_0x38feb5['name'],'interface':_0xb992b3,'enterAt':moment()['format'](_0x560a('0x2d')),'role':_0x38feb5['role'],'internal':_0x38feb5['internal']};_0x42ef64[_0x560a('0x2f')](function(_0x42266e){_0x16d150[_0x560a('0x30')](_[_0x560a('0x54')]({'channel':_0x42266e,'type':'LOGIN','data1':_0x560a('0x55'),'data2':_0xb992b3},_0x5ac917));if(_0x38feb5[_0x560a('0x51')]){_0x29f194[_0x560a('0x30')](_[_0x560a('0x54')]({'channel':_0x42266e,'type':_0x560a('0x2a'),'data1':'LOGININPAUSE'},_0x5ac917));}});return db['MemberReport'][_0x560a('0x36')](_0x16d150[_0x560a('0x56')](_0x29f194),{'individualHooks':!![]});}})['then'](function(){if(_0x38feb5){return _0x38feb5[_0x560a('0x29')]({'online':!![],'lastLoginAt':moment()['format'](_0x560a('0x2d')),'voicePause':_0x38feb5[_0x560a('0x51')]||![],'mailPause':_0x38feb5[_0x560a('0x51')]||![],'chatPause':_0x38feb5[_0x560a('0x51')]||![],'faxPause':_0x38feb5[_0x560a('0x51')]||![],'smsPause':_0x38feb5[_0x560a('0x51')]||![],'openchannelPause':_0x38feb5[_0x560a('0x51')]||![],'pauseType':_0x38feb5[_0x560a('0x51')]?'LOGININPAUSE':null,'lastPauseAt':moment()[_0x560a('0x2c')](_0x560a('0x2d')),'interface':_0xb992b3});}})[_0x560a('0xc')](function(_0x4cd8f8){_0x5dd836(_0x4cd8f8);})['catch'](function(_0x340611){_0x118cb8(_0x52facf[_0x560a('0x13')](0x1f4,_0x340611['message']));});});};
\ No newline at end of file