Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / user / user.rpc.js
index c000d92..69602dc 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc1da=['updateAttributes','getChannels','push','isNil','type','DEFAULT\x20PAUSE','uniqueid','bulkCreate','update','UnpauseUser','findOne','body','channel','isValidChannel','Unknown\x20channel','UserVoiceQueueRt','system','mail','fax','openchannel','whatsapp','set','%s%s','Pause','forEach','all','LogoutUser','phone','count','agent','../../config/license/util','agents','Maximum\x20login\x20has\x20been\x20reached','destroy','upsert','loginInPause','UserVoiceQueue.penalty','callysquare','merge','LOGININPAUSE','concat','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','redis','localhost','socket.io-emitter','./user.socket','request','then','info','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','code','error','User,\x20%s,\x20%s','message','result','catch','GetUser','User','options','where','attributes','limit','include','model','map','find','ShowUser','PauseUser','name','role','internal','interface','MemberReport','findAll','PAUSE','length','format','YYYY-MM-DD\x20HH:mm:ss'];(function(_0x5705bc,_0x8063c2){var _0x3c785d=function(_0x3537d0){while(--_0x3537d0){_0x5705bc['push'](_0x5705bc['shift']());}};_0x3c785d(++_0x8063c2);}(_0xc1da,0xdf));var _0xac1d=function(_0x262a4a,_0x60f91){_0x262a4a=_0x262a4a-0x0;var _0x590ff0=_0xc1da[_0x262a4a];return _0x590ff0;};'use strict';var _=require('lodash');var util=require(_0xac1d('0x0'));var moment=require(_0xac1d('0x1'));var BPromise=require(_0xac1d('0x2'));var rs=require(_0xac1d('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xac1d('0x4'))['db'];var utils=require(_0xac1d('0x5'));var logger=require(_0xac1d('0x6'))(_0xac1d('0x7'));var config=require(_0xac1d('0x8'));var jayson=require(_0xac1d('0x9'));var client=jayson['client'][_0xac1d('0xa')]({'port':0x232a});config[_0xac1d('0xb')]=_['defaults'](config[_0xac1d('0xb')],{'host':_0xac1d('0xc'),'port':0x18eb});var socket=require(_0xac1d('0xd'))(new Redis(config[_0xac1d('0xb')]));require(_0xac1d('0xe'))['register'](socket);function respondWithRpcPromise(_0x3221cc,_0x4af65e,_0x531815){return new BPromise(function(_0x1792fd,_0xbc48a){return client[_0xac1d('0xf')](_0x3221cc,_0x531815)[_0xac1d('0x10')](function(_0x4b160c){logger[_0xac1d('0x11')]('User,\x20%s,\x20%s',_0x4af65e,_0xac1d('0x12'));logger[_0xac1d('0x13')](_0xac1d('0x14'),_0x4af65e,_0xac1d('0x12'),JSON[_0xac1d('0x15')](_0x4b160c));if(_0x4b160c['error']){if(_0x4b160c['error'][_0xac1d('0x16')]===0x1f4){logger[_0xac1d('0x17')](_0xac1d('0x18'),_0x4af65e,_0x4b160c[_0xac1d('0x17')][_0xac1d('0x19')]);return _0xbc48a(_0x4b160c['error'][_0xac1d('0x19')]);}logger[_0xac1d('0x17')](_0xac1d('0x18'),_0x4af65e,_0x4b160c[_0xac1d('0x17')][_0xac1d('0x19')]);return _0x1792fd(_0x4b160c[_0xac1d('0x17')][_0xac1d('0x19')]);}else{logger[_0xac1d('0x11')]('User,\x20%s,\x20%s',_0x4af65e,_0xac1d('0x12'));_0x1792fd(_0x4b160c[_0xac1d('0x1a')][_0xac1d('0x19')]);}})[_0xac1d('0x1b')](function(_0x37bbdc){logger[_0xac1d('0x17')](_0xac1d('0x18'),_0x4af65e,_0x37bbdc);_0xbc48a(_0x37bbdc);});});}exports[_0xac1d('0x1c')]=function(_0x344791){var _0x200760=this;return new Promise(function(_0x4294e7,_0x278ed8){return db[_0xac1d('0x1d')]['findAll']({'raw':_0x344791[_0xac1d('0x1e')]?_0x344791['options']['raw']===undefined?!![]:![]:!![],'where':_0x344791['options']?_0x344791['options'][_0xac1d('0x1f')]||null:null,'attributes':_0x344791[_0xac1d('0x1e')]?_0x344791[_0xac1d('0x1e')][_0xac1d('0x20')]||null:null,'limit':_0x344791[_0xac1d('0x1e')]?_0x344791[_0xac1d('0x1e')][_0xac1d('0x21')]||null:null,'include':_0x344791[_0xac1d('0x1e')]?_0x344791[_0xac1d('0x1e')][_0xac1d('0x22')]?_['map'](_0x344791[_0xac1d('0x1e')][_0xac1d('0x22')],function(_0x440eb1){return{'model':db[_0x440eb1[_0xac1d('0x23')]],'as':_0x440eb1['as'],'attributes':_0x440eb1[_0xac1d('0x20')],'include':_0x440eb1[_0xac1d('0x22')]?_[_0xac1d('0x24')](_0x440eb1['include'],function(_0x435cf2){return{'model':db[_0x435cf2[_0xac1d('0x23')]],'as':_0x435cf2['as'],'attributes':_0x435cf2[_0xac1d('0x20')],'include':_0x435cf2['include']?_['map'](_0x435cf2[_0xac1d('0x22')],function(_0x1d2768){return{'model':db[_0x1d2768[_0xac1d('0x23')]],'as':_0x1d2768['as'],'attributes':_0x1d2768[_0xac1d('0x20')]};}):[]};}):[]};}):[]:[]})[_0xac1d('0x10')](function(_0x3c1829){logger['info'](_0xac1d('0x1c'),_0x344791);logger[_0xac1d('0x13')]('GetUser',_0x344791,JSON[_0xac1d('0x15')](_0x3c1829));_0x4294e7(_0x3c1829);})[_0xac1d('0x1b')](function(_0x44f6f6){logger[_0xac1d('0x17')](_0xac1d('0x1c'),_0x44f6f6[_0xac1d('0x19')],_0x344791);_0x278ed8(_0x200760[_0xac1d('0x17')](0x1f4,_0x44f6f6['message']));});});};exports['ShowUser']=function(_0x1ffde8){var _0x50edd3=this;return new Promise(function(_0x2e1e92,_0x80fe3d){return db[_0xac1d('0x1d')][_0xac1d('0x25')]({'raw':_0x1ffde8[_0xac1d('0x1e')]?_0x1ffde8['options']['raw']===undefined?!![]:![]:!![],'where':_0x1ffde8[_0xac1d('0x1e')]?_0x1ffde8[_0xac1d('0x1e')]['where']||null:null,'attributes':_0x1ffde8[_0xac1d('0x1e')]?_0x1ffde8[_0xac1d('0x1e')][_0xac1d('0x20')]||null:null,'include':_0x1ffde8[_0xac1d('0x1e')]?_0x1ffde8['options'][_0xac1d('0x22')]?_[_0xac1d('0x24')](_0x1ffde8['options'][_0xac1d('0x22')],function(_0x5522d1){return{'model':db[_0x5522d1['model']],'as':_0x5522d1['as'],'attributes':_0x5522d1[_0xac1d('0x20')],'include':_0x5522d1[_0xac1d('0x22')]?_[_0xac1d('0x24')](_0x5522d1['include'],function(_0x53f526){return{'model':db[_0x53f526[_0xac1d('0x23')]],'as':_0x53f526['as'],'attributes':_0x53f526[_0xac1d('0x20')],'include':_0x53f526['include']?_[_0xac1d('0x24')](_0x53f526['include'],function(_0x17e428){return{'model':db[_0x17e428[_0xac1d('0x23')]],'as':_0x17e428['as'],'attributes':_0x17e428[_0xac1d('0x20')]};}):[]};}):[]};}):[]:[]})[_0xac1d('0x10')](function(_0x283e2b){logger[_0xac1d('0x11')]('ShowUser',_0x1ffde8);logger[_0xac1d('0x13')](_0xac1d('0x26'),_0x1ffde8,JSON[_0xac1d('0x15')](_0x283e2b));_0x2e1e92(_0x283e2b);})['catch'](function(_0x4b0a0c){logger[_0xac1d('0x17')](_0xac1d('0x26'),_0x4b0a0c[_0xac1d('0x19')],_0x1ffde8);_0x80fe3d(_0x50edd3[_0xac1d('0x17')](0x1f4,_0x4b0a0c[_0xac1d('0x19')]));});});};exports[_0xac1d('0x27')]=function(_0x22fa59){var _0x4b2ce3=this;return new Promise(function(_0x310d10,_0x4290b6){var _0x4b7528;return db[_0xac1d('0x1d')][_0xac1d('0x25')]({'where':_0x22fa59['options'][_0xac1d('0x1f')]||{},'attributes':['id',_0xac1d('0x28'),_0xac1d('0x29'),_0xac1d('0x2a'),_0xac1d('0x2b')]})[_0xac1d('0x10')](function(_0x38bf4d){if(_0x38bf4d){_0x4b7528=_0x38bf4d;return db['UserVoiceQueueRt']['update']({'paused':0x1},{'where':{'UserId':_0x4b7528['id']},'individualHooks':!![]});}})['then'](function(){if(_0x4b7528){return db[_0xac1d('0x2c')][_0xac1d('0x2d')]({'where':{'membername':_0x4b7528[_0xac1d('0x28')],'type':_0xac1d('0x2e'),'exitAt':null}});}})['then'](function(_0x3d9213){if(_0x4b7528){if(_0x3d9213&&_0x3d9213[_0xac1d('0x2f')]){var _0x294c18=moment()[_0xac1d('0x30')](_0xac1d('0x31'));for(var _0x413977=0x0,_0x1e6097=_0x3d9213[_0xac1d('0x2f')];_0x413977<_0x1e6097;_0x413977++){_0x3d9213[_0x413977][_0xac1d('0x32')]({'exitAt':_0x294c18});}}}})[_0xac1d('0x10')](function(){if(_0x4b7528){var _0x20fc59=[];var _0x313b43=utils[_0xac1d('0x33')]();_0x313b43['forEach'](function(_0x1c47d9){_0x20fc59[_0xac1d('0x34')]({'channel':_0x1c47d9,'membername':_0x4b7528[_0xac1d('0x28')],'interface':_[_0xac1d('0x35')](_0x4b7528[_0xac1d('0x2b')])?util[_0xac1d('0x30')]('SIP/%s',_0x4b7528[_0xac1d('0x28')]):_0x4b7528[_0xac1d('0x2b')],'type':_0xac1d('0x2e'),'enterAt':moment()[_0xac1d('0x30')](_0xac1d('0x31')),'data1':_0x22fa59['body'][_0xac1d('0x36')]||_0xac1d('0x37'),'role':_0x4b7528[_0xac1d('0x29')],'internal':_0x4b7528[_0xac1d('0x2a')],'uniqueid':_0x22fa59['body'][_0xac1d('0x38')]||null});});return db['MemberReport'][_0xac1d('0x39')](_0x20fc59,{'individualHooks':!![]});}})['then'](function(){if(_0x4b7528){return _0x4b7528[_0xac1d('0x3a')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x22fa59['body'][_0xac1d('0x36')]||_0xac1d('0x37'),'lastPauseAt':moment()[_0xac1d('0x30')](_0xac1d('0x31'))});}})[_0xac1d('0x10')](function(_0x36be66){_0x310d10(_0x36be66);})[_0xac1d('0x1b')](function(_0x180d71){_0x4290b6(_0x4b2ce3[_0xac1d('0x17')](0x1f4,_0x180d71['message']));});});};exports[_0xac1d('0x3b')]=function(_0x55627d){var _0xf90f9d=this;return new Promise(function(_0x5d33ac,_0x102cd4){var _0x304d65;return db[_0xac1d('0x1d')][_0xac1d('0x3c')]({'where':_0x55627d[_0xac1d('0x1e')][_0xac1d('0x1f')]||{},'attributes':['id',_0xac1d('0x28')]})[_0xac1d('0x10')](function(_0x204c75){if(_0x204c75){_0x304d65=_0x204c75;if(_0x55627d[_0xac1d('0x3d')][_0xac1d('0x3e')]&&!utils[_0xac1d('0x3f')](_0x55627d[_0xac1d('0x3d')][_0xac1d('0x3e')])){throw new Error(_0xac1d('0x40'));}switch(_0x55627d[_0xac1d('0x3d')]['channel']){case'voice':return db[_0xac1d('0x41')]['update']({'paused':0x0},{'where':{'UserId':_0x304d65['id']}})['then'](function(){return db[_0xac1d('0x2c')][_0xac1d('0x25')]({'where':{'channel':_0x55627d[_0xac1d('0x3d')][_0xac1d('0x3e')],'membername':_0x304d65[_0xac1d('0x28')],'type':_0xac1d('0x2e'),'exitAt':null}});})[_0xac1d('0x10')](function(_0x48e9cf){if(_0x48e9cf){return _0x48e9cf[_0xac1d('0x3a')]({'exitAt':moment()[_0xac1d('0x30')](_0xac1d('0x31')),'data2':_0xac1d('0x42')},{'individualHooks':!![]});}return null;})[_0xac1d('0x10')](function(){return _0x304d65['update']({'voicePause':![]});});case _0xac1d('0x43'):case'chat':case _0xac1d('0x44'):case'sms':case _0xac1d('0x45'):case _0xac1d('0x46'):return db[_0xac1d('0x2c')][_0xac1d('0x25')]({'where':{'channel':_0x55627d['body']['channel'],'membername':_0x304d65[_0xac1d('0x28')],'type':_0xac1d('0x2e'),'exitAt':null}})[_0xac1d('0x10')](function(_0x29d5a2){return _0x29d5a2[_0xac1d('0x3a')]({'exitAt':moment()[_0xac1d('0x30')]('YYYY-MM-DD\x20HH:mm:ss'),'data2':'system'},{'individualHooks':!![]});})[_0xac1d('0x10')](function(){var _0x57c03e={};_[_0xac1d('0x47')](_0x57c03e,util[_0xac1d('0x30')](_0xac1d('0x48'),_0x55627d[_0xac1d('0x3d')][_0xac1d('0x3e')],_0xac1d('0x49')),![]);return _0x304d65[_0xac1d('0x3a')](_0x57c03e);});default:return db['UserVoiceQueueRt'][_0xac1d('0x3a')]({'paused':0x0},{'where':{'UserId':_0x304d65['id']}})['then'](function(){return db[_0xac1d('0x2c')]['findAll']({'where':{'membername':_0x304d65[_0xac1d('0x28')],'type':'PAUSE','exitAt':null}});})[_0xac1d('0x10')](function(_0x34da8d){var _0x153d08=[];_0x34da8d[_0xac1d('0x4a')](function(_0x2afd7c){_0x153d08[_0xac1d('0x34')](_0x2afd7c[_0xac1d('0x3a')]({'exitAt':moment()['format'](_0xac1d('0x31')),'data2':_0xac1d('0x42')}));});return BPromise[_0xac1d('0x4b')](_0x153d08);})[_0xac1d('0x10')](function(){return _0x304d65[_0xac1d('0x3a')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0xac1d('0x10')](function(_0x45bee8){_0x5d33ac(_0x45bee8);})[_0xac1d('0x1b')](function(_0x1a77dc){_0x102cd4(_0xf90f9d[_0xac1d('0x17')](0x1f4,_0x1a77dc[_0xac1d('0x19')]));});});};exports[_0xac1d('0x4c')]=function(_0x1cd848){var _0xa850=this;return new Promise(function(_0x4d5b03,_0x315f11){var _0x4132a3;return db[_0xac1d('0x1d')]['findOne']({'where':_0x1cd848[_0xac1d('0x1e')][_0xac1d('0x1f')]||{},'attributes':['id',_0xac1d('0x28')]})[_0xac1d('0x10')](function(_0x4dbdf1){if(_0x4dbdf1){_0x4132a3=_0x4dbdf1;return db[_0xac1d('0x41')]['destroy']({'where':{'membername':_0x4132a3['name']},'individualHooks':!![]});}})[_0xac1d('0x10')](function(){if(_0x4132a3){return db[_0xac1d('0x2c')][_0xac1d('0x2d')]({'where':{'membername':_0x4132a3[_0xac1d('0x28')],'exitAt':null}});}})[_0xac1d('0x10')](function(_0x1ea5a5){if(_0x4132a3){if(_0x1ea5a5&&_0x1ea5a5[_0xac1d('0x2f')]){var _0x157ffe=[];_0x1ea5a5[_0xac1d('0x4a')](function(_0x33ee1a){_0x157ffe[_0xac1d('0x34')](_0x33ee1a[_0xac1d('0x3a')]({'exitAt':moment()[_0xac1d('0x30')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0xac1d('0x4b')](_0x157ffe);}}})[_0xac1d('0x10')](function(){if(_0x4132a3){return _0x4132a3['update']({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xac1d('0x10')](function(_0x3304c4){_0x4d5b03(_0x3304c4);})[_0xac1d('0x1b')](function(_0x219aa2){_0x315f11(_0xa850[_0xac1d('0x17')](0x1f4,_0x219aa2[_0xac1d('0x19')]));});});};exports['LoginUser']=function(_0x33cfb4){var _0x3f08de=this;return new Promise(function(_0x1d9659,_0x326fc5){var _0x29fd0d;var _0x62d69a;var _0x535bcb;var _0x137f31;return db[_0xac1d('0x1d')][_0xac1d('0x3c')]({'where':_0x33cfb4[_0xac1d('0x1e')][_0xac1d('0x1f')]||{},'attributes':['id',_0xac1d('0x28'),_0xac1d('0x29'),'mobile',_0xac1d('0x4d'),_0xac1d('0x2a'),'loginInPause',_0xac1d('0x2b')]})[_0xac1d('0x10')](function(_0x5374c9){if(_0x5374c9){_0x29fd0d=_0x5374c9;_0x137f31=_0x33cfb4[_0xac1d('0x3d')]['interface']?_0x33cfb4['body'][_0xac1d('0x2b')]:util[_0xac1d('0x30')]('SIP/%s',_0x29fd0d[_0xac1d('0x28')]);return db['User'][_0xac1d('0x4e')]({'where':{'role':_0xac1d('0x4f'),'online':!![],'id':{'$ne':_0x29fd0d['id']}}});}})['then'](function(_0x3ab47f){if(_0x3ab47f){_0x535bcb=_0x3ab47f;return require(_0xac1d('0x50'))['getLicense']();}})['then'](function(_0x39ac23){if(_0x39ac23&&_0x39ac23[_0xac1d('0x51')]&&_0x535bcb>=_0x39ac23[_0xac1d('0x51')]){throw new Error(_0xac1d('0x52'));}})[_0xac1d('0x10')](function(){if(_0x29fd0d){return db[_0xac1d('0x41')][_0xac1d('0x53')]({'where':{'membername':_0x29fd0d[_0xac1d('0x28')]},'individualHooks':!![]});}})['then'](function(){if(_0x29fd0d){return _0x29fd0d['getVoiceQueues']({'raw':!![]});}})[_0xac1d('0x10')](function(_0x51dc95){if(_0x29fd0d){if(_0x51dc95){var _0x629bfd=[];_0x62d69a=_0x51dc95;if(_0x62d69a['length']){for(var _0x3e066d=0x0;_0x3e066d<_0x62d69a['length'];_0x3e066d++){_0x629bfd[_0xac1d('0x34')](db[_0xac1d('0x41')][_0xac1d('0x54')]({'membername':_0x29fd0d[_0xac1d('0x28')],'UserId':_0x29fd0d['id'],'queue_name':_0x62d69a[_0x3e066d][_0xac1d('0x28')],'VoiceQueueId':_0x62d69a[_0x3e066d]['id'],'interface':_0x137f31,'paused':_0x29fd0d[_0xac1d('0x55')]||![],'penalty':_0x62d69a[_0x3e066d][_0xac1d('0x56')]||0x0}));}return BPromise[_0xac1d('0x4b')](_0x629bfd);}}}})[_0xac1d('0x10')](function(){if(_0x29fd0d){return db[_0xac1d('0x2c')][_0xac1d('0x2d')]({'where':{'membername':_0x29fd0d[_0xac1d('0x28')],'exitAt':null}});}})[_0xac1d('0x10')](function(_0x6d0bc5){if(_0x29fd0d){if(_0x6d0bc5&&_0x6d0bc5[_0xac1d('0x2f')]){var _0x34b8e8=[];_0x6d0bc5[_0xac1d('0x4a')](function(_0x517057){_0x34b8e8[_0xac1d('0x34')](_0x517057[_0xac1d('0x3a')]({'exitAt':moment()[_0xac1d('0x30')](_0xac1d('0x31'))}));});return BPromise[_0xac1d('0x4b')](_0x34b8e8);}}})[_0xac1d('0x10')](function(_0x5dea60){if(_0x29fd0d){var _0x4d5ca4=[];var _0x47defb=[];var _0x4f9061=utils['getChannels']();var _0x5bfa57={'membername':_0x29fd0d[_0xac1d('0x28')],'interface':_0x137f31,'enterAt':moment()[_0xac1d('0x30')](_0xac1d('0x31')),'role':_0x29fd0d['role'],'internal':_0x29fd0d[_0xac1d('0x2a')]};_0x4f9061['forEach'](function(_0x50ba9c){_0x4d5ca4[_0xac1d('0x34')](_['merge']({'channel':_0x50ba9c,'type':'LOGIN','data1':_0xac1d('0x57'),'data2':_0x137f31},_0x5bfa57));if(_0x29fd0d[_0xac1d('0x55')]){_0x47defb[_0xac1d('0x34')](_[_0xac1d('0x58')]({'channel':_0x50ba9c,'type':_0xac1d('0x2e'),'data1':_0xac1d('0x59')},_0x5bfa57));}});return db[_0xac1d('0x2c')][_0xac1d('0x39')](_0x4d5ca4[_0xac1d('0x5a')](_0x47defb),{'individualHooks':!![]});}})[_0xac1d('0x10')](function(){if(_0x29fd0d){return _0x29fd0d['update']({'online':!![],'lastLoginAt':moment()[_0xac1d('0x30')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x29fd0d[_0xac1d('0x55')]||![],'mailPause':_0x29fd0d[_0xac1d('0x55')]||![],'chatPause':_0x29fd0d[_0xac1d('0x55')]||![],'faxPause':_0x29fd0d[_0xac1d('0x55')]||![],'smsPause':_0x29fd0d[_0xac1d('0x55')]||![],'openchannelPause':_0x29fd0d[_0xac1d('0x55')]||![],'pauseType':_0x29fd0d[_0xac1d('0x55')]?_0xac1d('0x59'):null,'lastPauseAt':moment()[_0xac1d('0x30')](_0xac1d('0x31')),'interface':_0x137f31});}})[_0xac1d('0x10')](function(_0x5818d7){_0x1d9659(_0x5818d7);})[_0xac1d('0x1b')](function(_0x5eec56){_0x326fc5(_0x3f08de[_0xac1d('0x17')](0x1f4,_0x5eec56[_0xac1d('0x19')]));});});};
\ No newline at end of file
+var _0xa2cd=['mail','fax','sms','channel','set','%s%s','Pause','push','all','LogoutUser','destroy','LoginUser','findOne','mobile','loginInPause','count','../../config/license/util','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','UserVoiceQueue.penalty','getChannels','LOGIN','callysquare','merge','LOGININPAUSE','concat','util','ioredis','../../config/utils','rpc','client','http','redis','defaults','localhost','socket.io-emitter','./user.socket','register','request','info','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','error','code','User,\x20%s,\x20%s','message','catch','User','options','raw','where','attributes','limit','map','model','include','then','GetUser','find','ShowUser','PauseUser','name','role','internal','interface','UserVoiceQueueRt','update','MemberReport','findAll','length','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','forEach','isNil','format','SIP/%s','body','DEFAULT\x20PAUSE','uniqueid','bulkCreate','UnpauseUser','isValidChannel','Unknown\x20channel','voice','PAUSE','system'];(function(_0x2da4d4,_0x342853){var _0x4174ac=function(_0x17217c){while(--_0x17217c){_0x2da4d4['push'](_0x2da4d4['shift']());}};_0x4174ac(++_0x342853);}(_0xa2cd,0x1e4));var _0xda2c=function(_0x5ddb1c,_0x5ea4df){_0x5ddb1c=_0x5ddb1c-0x0;var _0x354adc=_0xa2cd[_0x5ddb1c];return _0x354adc;};'use strict';var _=require('lodash');var util=require(_0xda2c('0x0'));var moment=require('moment');var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xda2c('0x1'));var db=require('../../mysqldb')['db'];var utils=require(_0xda2c('0x2'));var logger=require('../../config/logger')(_0xda2c('0x3'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xda2c('0x4')][_0xda2c('0x5')]({'port':0x232a});config[_0xda2c('0x6')]=_[_0xda2c('0x7')](config[_0xda2c('0x6')],{'host':_0xda2c('0x8'),'port':0x18eb});var socket=require(_0xda2c('0x9'))(new Redis(config['redis']));require(_0xda2c('0xa'))[_0xda2c('0xb')](socket);function respondWithRpcPromise(_0x1dc55d,_0x160e8b,_0x15d576){return new BPromise(function(_0x1b690f,_0x3f9863){return client[_0xda2c('0xc')](_0x1dc55d,_0x15d576)['then'](function(_0x14e58b){logger[_0xda2c('0xd')]('User,\x20%s,\x20%s',_0x160e8b,_0xda2c('0xe'));logger[_0xda2c('0xf')](_0xda2c('0x10'),_0x160e8b,_0xda2c('0xe'),JSON[_0xda2c('0x11')](_0x14e58b));if(_0x14e58b[_0xda2c('0x12')]){if(_0x14e58b['error'][_0xda2c('0x13')]===0x1f4){logger[_0xda2c('0x12')](_0xda2c('0x14'),_0x160e8b,_0x14e58b[_0xda2c('0x12')]['message']);return _0x3f9863(_0x14e58b[_0xda2c('0x12')][_0xda2c('0x15')]);}logger[_0xda2c('0x12')](_0xda2c('0x14'),_0x160e8b,_0x14e58b[_0xda2c('0x12')]['message']);return _0x1b690f(_0x14e58b[_0xda2c('0x12')][_0xda2c('0x15')]);}else{logger['info'](_0xda2c('0x14'),_0x160e8b,_0xda2c('0xe'));_0x1b690f(_0x14e58b['result']['message']);}})[_0xda2c('0x16')](function(_0x24631c){logger['error'](_0xda2c('0x14'),_0x160e8b,_0x24631c);_0x3f9863(_0x24631c);});});}exports['GetUser']=function(_0x4b980d){var _0x33ca61=this;return new Promise(function(_0x11b4df,_0x299c76){return db[_0xda2c('0x17')]['findAll']({'raw':_0x4b980d[_0xda2c('0x18')]?_0x4b980d[_0xda2c('0x18')][_0xda2c('0x19')]===undefined?!![]:![]:!![],'where':_0x4b980d[_0xda2c('0x18')]?_0x4b980d[_0xda2c('0x18')][_0xda2c('0x1a')]||null:null,'attributes':_0x4b980d[_0xda2c('0x18')]?_0x4b980d[_0xda2c('0x18')][_0xda2c('0x1b')]||null:null,'limit':_0x4b980d[_0xda2c('0x18')]?_0x4b980d[_0xda2c('0x18')][_0xda2c('0x1c')]||null:null,'include':_0x4b980d[_0xda2c('0x18')]?_0x4b980d['options']['include']?_[_0xda2c('0x1d')](_0x4b980d[_0xda2c('0x18')]['include'],function(_0x57d5b0){return{'model':db[_0x57d5b0[_0xda2c('0x1e')]],'as':_0x57d5b0['as'],'attributes':_0x57d5b0['attributes'],'include':_0x57d5b0[_0xda2c('0x1f')]?_[_0xda2c('0x1d')](_0x57d5b0[_0xda2c('0x1f')],function(_0x59e292){return{'model':db[_0x59e292[_0xda2c('0x1e')]],'as':_0x59e292['as'],'attributes':_0x59e292[_0xda2c('0x1b')],'include':_0x59e292[_0xda2c('0x1f')]?_[_0xda2c('0x1d')](_0x59e292[_0xda2c('0x1f')],function(_0x5e2723){return{'model':db[_0x5e2723['model']],'as':_0x5e2723['as'],'attributes':_0x5e2723[_0xda2c('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xda2c('0x20')](function(_0x3920d1){logger[_0xda2c('0xd')](_0xda2c('0x21'),_0x4b980d);logger['debug'](_0xda2c('0x21'),_0x4b980d,JSON['stringify'](_0x3920d1));_0x11b4df(_0x3920d1);})['catch'](function(_0x175906){logger[_0xda2c('0x12')]('GetUser',_0x175906['message'],_0x4b980d);_0x299c76(_0x33ca61[_0xda2c('0x12')](0x1f4,_0x175906[_0xda2c('0x15')]));});});};exports['ShowUser']=function(_0x2da82b){var _0x4ba2cc=this;return new Promise(function(_0x39966c,_0x43ab13){return db[_0xda2c('0x17')][_0xda2c('0x22')]({'raw':_0x2da82b[_0xda2c('0x18')]?_0x2da82b['options'][_0xda2c('0x19')]===undefined?!![]:![]:!![],'where':_0x2da82b[_0xda2c('0x18')]?_0x2da82b[_0xda2c('0x18')][_0xda2c('0x1a')]||null:null,'attributes':_0x2da82b[_0xda2c('0x18')]?_0x2da82b[_0xda2c('0x18')]['attributes']||null:null,'include':_0x2da82b['options']?_0x2da82b[_0xda2c('0x18')][_0xda2c('0x1f')]?_[_0xda2c('0x1d')](_0x2da82b['options']['include'],function(_0x4dd0c4){return{'model':db[_0x4dd0c4[_0xda2c('0x1e')]],'as':_0x4dd0c4['as'],'attributes':_0x4dd0c4['attributes'],'include':_0x4dd0c4['include']?_[_0xda2c('0x1d')](_0x4dd0c4[_0xda2c('0x1f')],function(_0x6ca043){return{'model':db[_0x6ca043[_0xda2c('0x1e')]],'as':_0x6ca043['as'],'attributes':_0x6ca043['attributes'],'include':_0x6ca043[_0xda2c('0x1f')]?_[_0xda2c('0x1d')](_0x6ca043[_0xda2c('0x1f')],function(_0x282ee5){return{'model':db[_0x282ee5[_0xda2c('0x1e')]],'as':_0x282ee5['as'],'attributes':_0x282ee5[_0xda2c('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xda2c('0x20')](function(_0x3f1507){logger[_0xda2c('0xd')](_0xda2c('0x23'),_0x2da82b);logger[_0xda2c('0xf')](_0xda2c('0x23'),_0x2da82b,JSON['stringify'](_0x3f1507));_0x39966c(_0x3f1507);})[_0xda2c('0x16')](function(_0x5c73f6){logger[_0xda2c('0x12')](_0xda2c('0x23'),_0x5c73f6[_0xda2c('0x15')],_0x2da82b);_0x43ab13(_0x4ba2cc['error'](0x1f4,_0x5c73f6[_0xda2c('0x15')]));});});};exports[_0xda2c('0x24')]=function(_0x4b248a){var _0x477531=this;return new Promise(function(_0x3496af,_0x206b30){var _0xa454e9;return db[_0xda2c('0x17')][_0xda2c('0x22')]({'where':_0x4b248a[_0xda2c('0x18')][_0xda2c('0x1a')]||{},'attributes':['id',_0xda2c('0x25'),_0xda2c('0x26'),_0xda2c('0x27'),_0xda2c('0x28')]})[_0xda2c('0x20')](function(_0x2bc58e){if(_0x2bc58e){_0xa454e9=_0x2bc58e;return db[_0xda2c('0x29')][_0xda2c('0x2a')]({'paused':0x1},{'where':{'UserId':_0xa454e9['id']},'individualHooks':!![]});}})[_0xda2c('0x20')](function(){if(_0xa454e9){return db[_0xda2c('0x2b')][_0xda2c('0x2c')]({'where':{'membername':_0xa454e9[_0xda2c('0x25')],'type':'PAUSE','exitAt':null}});}})[_0xda2c('0x20')](function(_0x388488){if(_0xa454e9){if(_0x388488&&_0x388488[_0xda2c('0x2d')]){var _0x53fb04=moment()['format'](_0xda2c('0x2e'));for(var _0x23957c=0x0,_0x1ca677=_0x388488[_0xda2c('0x2d')];_0x23957c<_0x1ca677;_0x23957c++){_0x388488[_0x23957c][_0xda2c('0x2f')]({'exitAt':_0x53fb04});}}}})[_0xda2c('0x20')](function(){if(_0xa454e9){var _0x262cdf=[];var _0x2c4170=utils['getChannels']();_0x2c4170[_0xda2c('0x30')](function(_0x38625e){_0x262cdf['push']({'channel':_0x38625e,'membername':_0xa454e9[_0xda2c('0x25')],'interface':_[_0xda2c('0x31')](_0xa454e9[_0xda2c('0x28')])?util[_0xda2c('0x32')](_0xda2c('0x33'),_0xa454e9['name']):_0xa454e9[_0xda2c('0x28')],'type':'PAUSE','enterAt':moment()['format'](_0xda2c('0x2e')),'data1':_0x4b248a[_0xda2c('0x34')]['type']||_0xda2c('0x35'),'role':_0xa454e9[_0xda2c('0x26')],'internal':_0xa454e9[_0xda2c('0x27')],'uniqueid':_0x4b248a[_0xda2c('0x34')][_0xda2c('0x36')]||null});});return db['MemberReport'][_0xda2c('0x37')](_0x262cdf,{'individualHooks':!![]});}})[_0xda2c('0x20')](function(){if(_0xa454e9){return _0xa454e9[_0xda2c('0x2a')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x4b248a[_0xda2c('0x34')]['type']||_0xda2c('0x35'),'lastPauseAt':moment()['format'](_0xda2c('0x2e'))});}})['then'](function(_0x1522ce){_0x3496af(_0x1522ce);})[_0xda2c('0x16')](function(_0x4eec56){_0x206b30(_0x477531[_0xda2c('0x12')](0x1f4,_0x4eec56[_0xda2c('0x15')]));});});};exports[_0xda2c('0x38')]=function(_0x28d209){var _0x1bd6f8=this;return new Promise(function(_0x6a89b8,_0xfb28a6){var _0x3b1445;return db['User']['findOne']({'where':_0x28d209['options'][_0xda2c('0x1a')]||{},'attributes':['id','name']})[_0xda2c('0x20')](function(_0xe28f2a){if(_0xe28f2a){_0x3b1445=_0xe28f2a;if(_0x28d209[_0xda2c('0x34')]['channel']&&!utils[_0xda2c('0x39')](_0x28d209['body']['channel'])){throw new Error(_0xda2c('0x3a'));}switch(_0x28d209[_0xda2c('0x34')]['channel']){case _0xda2c('0x3b'):return db['UserVoiceQueueRt'][_0xda2c('0x2a')]({'paused':0x0},{'where':{'UserId':_0x3b1445['id']}})['then'](function(){return db['MemberReport'][_0xda2c('0x22')]({'where':{'channel':_0x28d209['body']['channel'],'membername':_0x3b1445[_0xda2c('0x25')],'type':_0xda2c('0x3c'),'exitAt':null}});})[_0xda2c('0x20')](function(_0x35814b){if(_0x35814b){return _0x35814b[_0xda2c('0x2a')]({'exitAt':moment()[_0xda2c('0x32')](_0xda2c('0x2e')),'data2':_0xda2c('0x3d')},{'individualHooks':!![]});}return null;})[_0xda2c('0x20')](function(){return _0x3b1445[_0xda2c('0x2a')]({'voicePause':![]});});case _0xda2c('0x3e'):case'chat':case _0xda2c('0x3f'):case _0xda2c('0x40'):case'openchannel':case'whatsapp':return db[_0xda2c('0x2b')]['find']({'where':{'channel':_0x28d209[_0xda2c('0x34')][_0xda2c('0x41')],'membername':_0x3b1445[_0xda2c('0x25')],'type':'PAUSE','exitAt':null}})['then'](function(_0x1021e6){return _0x1021e6[_0xda2c('0x2a')]({'exitAt':moment()[_0xda2c('0x32')]('YYYY-MM-DD\x20HH:mm:ss'),'data2':_0xda2c('0x3d')},{'individualHooks':!![]});})['then'](function(){var _0x5da266={};_[_0xda2c('0x42')](_0x5da266,util[_0xda2c('0x32')](_0xda2c('0x43'),_0x28d209['body']['channel'],_0xda2c('0x44')),![]);return _0x3b1445['update'](_0x5da266);});default:return db[_0xda2c('0x29')][_0xda2c('0x2a')]({'paused':0x0},{'where':{'UserId':_0x3b1445['id']}})['then'](function(){return db[_0xda2c('0x2b')][_0xda2c('0x2c')]({'where':{'membername':_0x3b1445[_0xda2c('0x25')],'type':_0xda2c('0x3c'),'exitAt':null}});})[_0xda2c('0x20')](function(_0x39b682){var _0x1bf8a0=[];_0x39b682[_0xda2c('0x30')](function(_0x24d065){_0x1bf8a0[_0xda2c('0x45')](_0x24d065[_0xda2c('0x2a')]({'exitAt':moment()[_0xda2c('0x32')](_0xda2c('0x2e')),'data2':_0xda2c('0x3d')}));});return BPromise[_0xda2c('0x46')](_0x1bf8a0);})[_0xda2c('0x20')](function(){return _0x3b1445['update']({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0xda2c('0x20')](function(_0x10f683){_0x6a89b8(_0x10f683);})[_0xda2c('0x16')](function(_0x4fc32d){_0xfb28a6(_0x1bd6f8['error'](0x1f4,_0x4fc32d[_0xda2c('0x15')]));});});};exports[_0xda2c('0x47')]=function(_0x5a4362){var _0x49b934=this;return new Promise(function(_0x4bfede,_0x11bc96){var _0x10b90d;return db[_0xda2c('0x17')]['findOne']({'where':_0x5a4362[_0xda2c('0x18')]['where']||{},'attributes':['id',_0xda2c('0x25')]})[_0xda2c('0x20')](function(_0x560afd){if(_0x560afd){_0x10b90d=_0x560afd;return db[_0xda2c('0x29')][_0xda2c('0x48')]({'where':{'membername':_0x10b90d[_0xda2c('0x25')]},'individualHooks':!![]});}})[_0xda2c('0x20')](function(){if(_0x10b90d){return db[_0xda2c('0x2b')][_0xda2c('0x2c')]({'where':{'membername':_0x10b90d['name'],'exitAt':null}});}})[_0xda2c('0x20')](function(_0x42871f){if(_0x10b90d){if(_0x42871f&&_0x42871f[_0xda2c('0x2d')]){var _0x4ea42a=[];_0x42871f[_0xda2c('0x30')](function(_0x27ef23){_0x4ea42a['push'](_0x27ef23['update']({'exitAt':moment()[_0xda2c('0x32')](_0xda2c('0x2e'))}));});return BPromise['all'](_0x4ea42a);}}})[_0xda2c('0x20')](function(){if(_0x10b90d){return _0x10b90d['update']({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xda2c('0x20')](function(_0x5cfe53){_0x4bfede(_0x5cfe53);})[_0xda2c('0x16')](function(_0x18d212){_0x11bc96(_0x49b934['error'](0x1f4,_0x18d212[_0xda2c('0x15')]));});});};exports[_0xda2c('0x49')]=function(_0x5c00a3){var _0x39cad6=this;return new Promise(function(_0x58787d,_0x9b3527){var _0x3e1fb1;var _0x27b927;var _0x5eaae6;var _0x424e3e;return db[_0xda2c('0x17')][_0xda2c('0x4a')]({'where':_0x5c00a3[_0xda2c('0x18')]['where']||{},'attributes':['id',_0xda2c('0x25'),_0xda2c('0x26'),_0xda2c('0x4b'),'phone','internal',_0xda2c('0x4c'),_0xda2c('0x28')]})['then'](function(_0x28eb38){if(_0x28eb38){_0x3e1fb1=_0x28eb38;_0x424e3e=_0x5c00a3[_0xda2c('0x34')]['interface']?_0x5c00a3[_0xda2c('0x34')][_0xda2c('0x28')]:util[_0xda2c('0x32')](_0xda2c('0x33'),_0x3e1fb1[_0xda2c('0x25')]);return db[_0xda2c('0x17')][_0xda2c('0x4d')]({'where':{'role':'agent','online':!![],'id':{'$ne':_0x3e1fb1['id']}}});}})['then'](function(_0x3373db){if(_0x3373db){_0x5eaae6=_0x3373db;return require(_0xda2c('0x4e'))[_0xda2c('0x4f')]();}})['then'](function(_0x5eb1ea){if(_0x5eb1ea&&_0x5eb1ea[_0xda2c('0x50')]&&_0x5eaae6>=_0x5eb1ea[_0xda2c('0x50')]){throw new Error(_0xda2c('0x51'));}})['then'](function(){if(_0x3e1fb1){return db[_0xda2c('0x29')][_0xda2c('0x48')]({'where':{'membername':_0x3e1fb1[_0xda2c('0x25')]},'individualHooks':!![]});}})[_0xda2c('0x20')](function(){if(_0x3e1fb1){return _0x3e1fb1[_0xda2c('0x52')]({'raw':!![]});}})[_0xda2c('0x20')](function(_0x44ff5d){if(_0x3e1fb1){if(_0x44ff5d){var _0x51adaf=[];_0x27b927=_0x44ff5d;if(_0x27b927['length']){for(var _0x514c9b=0x0;_0x514c9b<_0x27b927[_0xda2c('0x2d')];_0x514c9b++){_0x51adaf['push'](db['UserVoiceQueueRt'][_0xda2c('0x53')]({'membername':_0x3e1fb1[_0xda2c('0x25')],'UserId':_0x3e1fb1['id'],'queue_name':_0x27b927[_0x514c9b][_0xda2c('0x25')],'VoiceQueueId':_0x27b927[_0x514c9b]['id'],'interface':_0x424e3e,'paused':_0x3e1fb1[_0xda2c('0x4c')]||![],'penalty':_0x27b927[_0x514c9b][_0xda2c('0x54')]||0x0}));}return BPromise[_0xda2c('0x46')](_0x51adaf);}}}})[_0xda2c('0x20')](function(){if(_0x3e1fb1){return db[_0xda2c('0x2b')][_0xda2c('0x2c')]({'where':{'membername':_0x3e1fb1['name'],'exitAt':null}});}})[_0xda2c('0x20')](function(_0x796fda){if(_0x3e1fb1){if(_0x796fda&&_0x796fda[_0xda2c('0x2d')]){var _0x4c204a=[];_0x796fda[_0xda2c('0x30')](function(_0x193ae1){_0x4c204a[_0xda2c('0x45')](_0x193ae1[_0xda2c('0x2a')]({'exitAt':moment()[_0xda2c('0x32')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0xda2c('0x46')](_0x4c204a);}}})[_0xda2c('0x20')](function(_0x104f61){if(_0x3e1fb1){var _0x416640=[];var _0x2f5156=[];var _0x37db7f=utils[_0xda2c('0x55')]();var _0x2aaae8={'membername':_0x3e1fb1[_0xda2c('0x25')],'interface':_0x424e3e,'enterAt':moment()[_0xda2c('0x32')](_0xda2c('0x2e')),'role':_0x3e1fb1['role'],'internal':_0x3e1fb1[_0xda2c('0x27')]};_0x37db7f[_0xda2c('0x30')](function(_0x2ab17b){_0x416640['push'](_['merge']({'channel':_0x2ab17b,'type':_0xda2c('0x56'),'data1':_0xda2c('0x57'),'data2':_0x424e3e},_0x2aaae8));if(_0x3e1fb1['loginInPause']){_0x2f5156[_0xda2c('0x45')](_[_0xda2c('0x58')]({'channel':_0x2ab17b,'type':_0xda2c('0x3c'),'data1':_0xda2c('0x59')},_0x2aaae8));}});return db[_0xda2c('0x2b')][_0xda2c('0x37')](_0x416640[_0xda2c('0x5a')](_0x2f5156),{'individualHooks':!![]});}})[_0xda2c('0x20')](function(){if(_0x3e1fb1){return _0x3e1fb1[_0xda2c('0x2a')]({'online':!![],'lastLoginAt':moment()[_0xda2c('0x32')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x3e1fb1[_0xda2c('0x4c')]||![],'mailPause':_0x3e1fb1[_0xda2c('0x4c')]||![],'chatPause':_0x3e1fb1[_0xda2c('0x4c')]||![],'faxPause':_0x3e1fb1['loginInPause']||![],'smsPause':_0x3e1fb1[_0xda2c('0x4c')]||![],'openchannelPause':_0x3e1fb1[_0xda2c('0x4c')]||![],'pauseType':_0x3e1fb1[_0xda2c('0x4c')]?_0xda2c('0x59'):null,'lastPauseAt':moment()[_0xda2c('0x32')]('YYYY-MM-DD\x20HH:mm:ss'),'interface':_0x424e3e});}})[_0xda2c('0x20')](function(_0x284e90){_0x58787d(_0x284e90);})[_0xda2c('0x16')](function(_0x328628){_0x9b3527(_0x39cad6[_0xda2c('0x12')](0x1f4,_0x328628[_0xda2c('0x15')]));});});};
\ No newline at end of file