Built motion from commit (unavailable).|2.5.11
[motion2.git] / server / api / user / user.rpc.js
index 11918ff..710a59c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8efc=['moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','defaults','redis','localhost','./user.socket','register','request','then','info','User,\x20%s,\x20%s','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','User','findAll','options','raw','where','attributes','include','map','model','GetUser','ShowUser','find','PauseUser','name','interface','UserVoiceQueueRt','update','PAUSE','format','length','updateAttributes','forEach','push','isNil','YYYY-MM-DD\x20HH:mm:ss','body','DEFAULT\x20PAUSE','role','internal','MemberReport','bulkCreate','UnpauseUser','channel','isValidChannel','Unknown\x20channel','voice','system','chat','fax','sms','set','%s%s','Pause','all','destroy','findOne','mobile','loginInPause','SIP/%s','count','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','UserVoiceQueue.penalty','getChannels','merge','callysquare','concat','LOGININPAUSE','util'];(function(_0x1353f9,_0x442a93){var _0x32d8e0=function(_0x38ab8e){while(--_0x38ab8e){_0x1353f9['push'](_0x1353f9['shift']());}};_0x32d8e0(++_0x442a93);}(_0x8efc,0xb3));var _0xc8ef=function(_0x401a4d,_0x4bb835){_0x401a4d=_0x401a4d-0x0;var _0x1faaff=_0x8efc[_0x401a4d];return _0x1faaff;};'use strict';var _=require('lodash');var util=require(_0xc8ef('0x0'));var moment=require(_0xc8ef('0x1'));var BPromise=require(_0xc8ef('0x2'));var rs=require(_0xc8ef('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xc8ef('0x4'))['db'];var utils=require(_0xc8ef('0x5'));var logger=require(_0xc8ef('0x6'))('rpc');var config=require(_0xc8ef('0x7'));var jayson=require(_0xc8ef('0x8'));var client=jayson[_0xc8ef('0x9')][_0xc8ef('0xa')]({'port':0x232a});config['redis']=_[_0xc8ef('0xb')](config[_0xc8ef('0xc')],{'host':_0xc8ef('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xc8ef('0xc')]));require(_0xc8ef('0xe'))[_0xc8ef('0xf')](socket);function respondWithRpcPromise(_0xcc3c21,_0x56cfb1,_0x315d93){return new BPromise(function(_0x574588,_0x45dbd3){return client[_0xc8ef('0x10')](_0xcc3c21,_0x315d93)[_0xc8ef('0x11')](function(_0x29d96b){logger[_0xc8ef('0x12')](_0xc8ef('0x13'),_0x56cfb1,_0xc8ef('0x14'));logger[_0xc8ef('0x15')](_0xc8ef('0x16'),_0x56cfb1,_0xc8ef('0x14'),JSON[_0xc8ef('0x17')](_0x29d96b));if(_0x29d96b[_0xc8ef('0x18')]){if(_0x29d96b[_0xc8ef('0x18')][_0xc8ef('0x19')]===0x1f4){logger[_0xc8ef('0x18')](_0xc8ef('0x13'),_0x56cfb1,_0x29d96b[_0xc8ef('0x18')][_0xc8ef('0x1a')]);return _0x45dbd3(_0x29d96b[_0xc8ef('0x18')][_0xc8ef('0x1a')]);}logger[_0xc8ef('0x18')](_0xc8ef('0x13'),_0x56cfb1,_0x29d96b['error'][_0xc8ef('0x1a')]);return _0x574588(_0x29d96b[_0xc8ef('0x18')][_0xc8ef('0x1a')]);}else{logger[_0xc8ef('0x12')](_0xc8ef('0x13'),_0x56cfb1,_0xc8ef('0x14'));_0x574588(_0x29d96b[_0xc8ef('0x1b')][_0xc8ef('0x1a')]);}})[_0xc8ef('0x1c')](function(_0x3591c){logger['error'](_0xc8ef('0x13'),_0x56cfb1,_0x3591c);_0x45dbd3(_0x3591c);});});}exports['GetUser']=function(_0x3deec3){var _0x4c020e=this;return new Promise(function(_0x4648b1,_0x4ff970){return db[_0xc8ef('0x1d')][_0xc8ef('0x1e')]({'raw':_0x3deec3[_0xc8ef('0x1f')]?_0x3deec3[_0xc8ef('0x1f')][_0xc8ef('0x20')]===undefined?!![]:![]:!![],'where':_0x3deec3['options']?_0x3deec3[_0xc8ef('0x1f')][_0xc8ef('0x21')]||null:null,'attributes':_0x3deec3[_0xc8ef('0x1f')]?_0x3deec3['options'][_0xc8ef('0x22')]||null:null,'limit':_0x3deec3['options']?_0x3deec3['options']['limit']||null:null,'include':_0x3deec3['options']?_0x3deec3[_0xc8ef('0x1f')][_0xc8ef('0x23')]?_[_0xc8ef('0x24')](_0x3deec3[_0xc8ef('0x1f')][_0xc8ef('0x23')],function(_0x319c09){return{'model':db[_0x319c09[_0xc8ef('0x25')]],'as':_0x319c09['as'],'attributes':_0x319c09[_0xc8ef('0x22')],'include':_0x319c09[_0xc8ef('0x23')]?_[_0xc8ef('0x24')](_0x319c09[_0xc8ef('0x23')],function(_0x328a91){return{'model':db[_0x328a91[_0xc8ef('0x25')]],'as':_0x328a91['as'],'attributes':_0x328a91[_0xc8ef('0x22')],'include':_0x328a91['include']?_[_0xc8ef('0x24')](_0x328a91[_0xc8ef('0x23')],function(_0x522500){return{'model':db[_0x522500['model']],'as':_0x522500['as'],'attributes':_0x522500[_0xc8ef('0x22')]};}):[]};}):[]};}):[]:[]})['then'](function(_0xe5e45b){logger['info'](_0xc8ef('0x26'),_0x3deec3);logger['debug'](_0xc8ef('0x26'),_0x3deec3,JSON[_0xc8ef('0x17')](_0xe5e45b));_0x4648b1(_0xe5e45b);})['catch'](function(_0x5f40c9){logger[_0xc8ef('0x18')](_0xc8ef('0x26'),_0x5f40c9['message'],_0x3deec3);_0x4ff970(_0x4c020e[_0xc8ef('0x18')](0x1f4,_0x5f40c9[_0xc8ef('0x1a')]));});});};exports[_0xc8ef('0x27')]=function(_0x3555f7){var _0x2985cc=this;return new Promise(function(_0xa46ce0,_0x2c2114){return db[_0xc8ef('0x1d')][_0xc8ef('0x28')]({'raw':_0x3555f7[_0xc8ef('0x1f')]?_0x3555f7[_0xc8ef('0x1f')][_0xc8ef('0x20')]===undefined?!![]:![]:!![],'where':_0x3555f7['options']?_0x3555f7[_0xc8ef('0x1f')][_0xc8ef('0x21')]||null:null,'attributes':_0x3555f7[_0xc8ef('0x1f')]?_0x3555f7[_0xc8ef('0x1f')]['attributes']||null:null,'include':_0x3555f7[_0xc8ef('0x1f')]?_0x3555f7[_0xc8ef('0x1f')]['include']?_[_0xc8ef('0x24')](_0x3555f7[_0xc8ef('0x1f')]['include'],function(_0x541e8c){return{'model':db[_0x541e8c[_0xc8ef('0x25')]],'as':_0x541e8c['as'],'attributes':_0x541e8c[_0xc8ef('0x22')],'include':_0x541e8c[_0xc8ef('0x23')]?_['map'](_0x541e8c['include'],function(_0x32dd28){return{'model':db[_0x32dd28[_0xc8ef('0x25')]],'as':_0x32dd28['as'],'attributes':_0x32dd28[_0xc8ef('0x22')],'include':_0x32dd28[_0xc8ef('0x23')]?_[_0xc8ef('0x24')](_0x32dd28['include'],function(_0x309495){return{'model':db[_0x309495[_0xc8ef('0x25')]],'as':_0x309495['as'],'attributes':_0x309495[_0xc8ef('0x22')]};}):[]};}):[]};}):[]:[]})[_0xc8ef('0x11')](function(_0x373ca1){logger[_0xc8ef('0x12')]('ShowUser',_0x3555f7);logger[_0xc8ef('0x15')](_0xc8ef('0x27'),_0x3555f7,JSON['stringify'](_0x373ca1));_0xa46ce0(_0x373ca1);})['catch'](function(_0x5ab0d4){logger['error'](_0xc8ef('0x27'),_0x5ab0d4['message'],_0x3555f7);_0x2c2114(_0x2985cc[_0xc8ef('0x18')](0x1f4,_0x5ab0d4[_0xc8ef('0x1a')]));});});};exports[_0xc8ef('0x29')]=function(_0x48398c){var _0x3f7b94=this;return new Promise(function(_0x38fe94,_0x37fd40){var _0xdefc03;return db['User'][_0xc8ef('0x28')]({'where':_0x48398c[_0xc8ef('0x1f')][_0xc8ef('0x21')]||{},'attributes':['id',_0xc8ef('0x2a'),'role','internal',_0xc8ef('0x2b')]})[_0xc8ef('0x11')](function(_0x27dfaf){if(_0x27dfaf){_0xdefc03=_0x27dfaf;return db[_0xc8ef('0x2c')][_0xc8ef('0x2d')]({'paused':0x1},{'where':{'UserId':_0xdefc03['id']},'individualHooks':!![]});}})['then'](function(){if(_0xdefc03){return db['MemberReport'][_0xc8ef('0x1e')]({'where':{'membername':_0xdefc03['name'],'type':_0xc8ef('0x2e'),'exitAt':null}});}})[_0xc8ef('0x11')](function(_0x441f52){if(_0xdefc03){if(_0x441f52&&_0x441f52['length']){var _0x2a612e=moment()[_0xc8ef('0x2f')]('YYYY-MM-DD\x20HH:mm:ss');for(var _0x3cd290=0x0,_0x4ebbe7=_0x441f52[_0xc8ef('0x30')];_0x3cd290<_0x4ebbe7;_0x3cd290++){_0x441f52[_0x3cd290][_0xc8ef('0x31')]({'exitAt':_0x2a612e});}}}})[_0xc8ef('0x11')](function(){if(_0xdefc03){var _0x585817=[];var _0x5b1ef1=utils['getChannels']();_0x5b1ef1[_0xc8ef('0x32')](function(_0x39fa06){_0x585817[_0xc8ef('0x33')]({'channel':_0x39fa06,'membername':_0xdefc03[_0xc8ef('0x2a')],'interface':_[_0xc8ef('0x34')](_0xdefc03[_0xc8ef('0x2b')])?util[_0xc8ef('0x2f')]('SIP/%s',_0xdefc03['name']):_0xdefc03[_0xc8ef('0x2b')],'type':_0xc8ef('0x2e'),'enterAt':moment()[_0xc8ef('0x2f')](_0xc8ef('0x35')),'data1':_0x48398c[_0xc8ef('0x36')]['type']||_0xc8ef('0x37'),'role':_0xdefc03[_0xc8ef('0x38')],'internal':_0xdefc03[_0xc8ef('0x39')],'uniqueid':_0x48398c[_0xc8ef('0x36')]['uniqueid']||null});});return db[_0xc8ef('0x3a')][_0xc8ef('0x3b')](_0x585817,{'individualHooks':!![]});}})[_0xc8ef('0x11')](function(){if(_0xdefc03){return _0xdefc03['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x48398c[_0xc8ef('0x36')]['type']||_0xc8ef('0x37'),'lastPauseAt':moment()['format'](_0xc8ef('0x35'))});}})[_0xc8ef('0x11')](function(_0x240de4){_0x38fe94(_0x240de4);})[_0xc8ef('0x1c')](function(_0xab53f3){_0x37fd40(_0x3f7b94[_0xc8ef('0x18')](0x1f4,_0xab53f3[_0xc8ef('0x1a')]));});});};exports[_0xc8ef('0x3c')]=function(_0x49eac5){var _0x411923=this;return new Promise(function(_0x32167f,_0x4be92d){var _0x587ddb;return db[_0xc8ef('0x1d')]['findOne']({'where':_0x49eac5[_0xc8ef('0x1f')]['where']||{},'attributes':['id',_0xc8ef('0x2a')]})['then'](function(_0x45e799){if(_0x45e799){_0x587ddb=_0x45e799;if(_0x49eac5[_0xc8ef('0x36')][_0xc8ef('0x3d')]&&!utils[_0xc8ef('0x3e')](_0x49eac5[_0xc8ef('0x36')]['channel'])){throw new Error(_0xc8ef('0x3f'));}switch(_0x49eac5[_0xc8ef('0x36')][_0xc8ef('0x3d')]){case _0xc8ef('0x40'):return db[_0xc8ef('0x2c')][_0xc8ef('0x2d')]({'paused':0x0},{'where':{'UserId':_0x587ddb['id']}})['then'](function(){return db['MemberReport'][_0xc8ef('0x28')]({'where':{'channel':_0x49eac5[_0xc8ef('0x36')]['channel'],'membername':_0x587ddb['name'],'type':_0xc8ef('0x2e'),'exitAt':null}});})[_0xc8ef('0x11')](function(_0x5c1c72){if(_0x5c1c72){return _0x5c1c72['update']({'exitAt':moment()[_0xc8ef('0x2f')](_0xc8ef('0x35')),'data2':_0xc8ef('0x41')},{'individualHooks':!![]});}return null;})[_0xc8ef('0x11')](function(){return _0x587ddb[_0xc8ef('0x2d')]({'voicePause':![]});});case'mail':case _0xc8ef('0x42'):case _0xc8ef('0x43'):case _0xc8ef('0x44'):case'openchannel':case'whatsapp':return db[_0xc8ef('0x3a')][_0xc8ef('0x28')]({'where':{'channel':_0x49eac5[_0xc8ef('0x36')][_0xc8ef('0x3d')],'membername':_0x587ddb[_0xc8ef('0x2a')],'type':_0xc8ef('0x2e'),'exitAt':null}})[_0xc8ef('0x11')](function(_0xe64c5){return _0xe64c5[_0xc8ef('0x2d')]({'exitAt':moment()['format'](_0xc8ef('0x35')),'data2':'system'},{'individualHooks':!![]});})[_0xc8ef('0x11')](function(){var _0x40607a={};_[_0xc8ef('0x45')](_0x40607a,util[_0xc8ef('0x2f')](_0xc8ef('0x46'),_0x49eac5[_0xc8ef('0x36')]['channel'],_0xc8ef('0x47')),![]);return _0x587ddb[_0xc8ef('0x2d')](_0x40607a);});default:return db[_0xc8ef('0x2c')][_0xc8ef('0x2d')]({'paused':0x0},{'where':{'UserId':_0x587ddb['id']}})[_0xc8ef('0x11')](function(){return db[_0xc8ef('0x3a')][_0xc8ef('0x1e')]({'where':{'membername':_0x587ddb[_0xc8ef('0x2a')],'type':_0xc8ef('0x2e'),'exitAt':null}});})[_0xc8ef('0x11')](function(_0x5128f2){var _0x2b6543=[];_0x5128f2[_0xc8ef('0x32')](function(_0x56f8cb){_0x2b6543[_0xc8ef('0x33')](_0x56f8cb['update']({'exitAt':moment()[_0xc8ef('0x2f')](_0xc8ef('0x35')),'data2':'system'}));});return BPromise[_0xc8ef('0x48')](_0x2b6543);})[_0xc8ef('0x11')](function(){return _0x587ddb[_0xc8ef('0x2d')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})['then'](function(_0x2ed3ea){_0x32167f(_0x2ed3ea);})[_0xc8ef('0x1c')](function(_0x1b9c37){_0x4be92d(_0x411923[_0xc8ef('0x18')](0x1f4,_0x1b9c37[_0xc8ef('0x1a')]));});});};exports['LogoutUser']=function(_0xd832de){var _0x1644e1=this;return new Promise(function(_0x704534,_0x26d9f1){var _0x41cab2;return db[_0xc8ef('0x1d')]['findOne']({'where':_0xd832de['options'][_0xc8ef('0x21')]||{},'attributes':['id',_0xc8ef('0x2a')]})[_0xc8ef('0x11')](function(_0x5928d9){if(_0x5928d9){_0x41cab2=_0x5928d9;return db[_0xc8ef('0x2c')][_0xc8ef('0x49')]({'where':{'membername':_0x41cab2['name']},'individualHooks':!![]});}})['then'](function(){if(_0x41cab2){return db['MemberReport'][_0xc8ef('0x1e')]({'where':{'membername':_0x41cab2[_0xc8ef('0x2a')],'exitAt':null}});}})[_0xc8ef('0x11')](function(_0x28a5c6){if(_0x41cab2){if(_0x28a5c6&&_0x28a5c6[_0xc8ef('0x30')]){var _0xf691bc=[];_0x28a5c6[_0xc8ef('0x32')](function(_0x32c5a6){_0xf691bc[_0xc8ef('0x33')](_0x32c5a6[_0xc8ef('0x2d')]({'exitAt':moment()['format'](_0xc8ef('0x35'))}));});return BPromise[_0xc8ef('0x48')](_0xf691bc);}}})[_0xc8ef('0x11')](function(){if(_0x41cab2){return _0x41cab2[_0xc8ef('0x2d')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xc8ef('0x11')](function(_0x405672){_0x704534(_0x405672);})['catch'](function(_0x38e239){_0x26d9f1(_0x1644e1['error'](0x1f4,_0x38e239['message']));});});};exports['LoginUser']=function(_0x20d3e5){var _0x24159f=this;return new Promise(function(_0x278159,_0x20c829){var _0x2229df;var _0x3b2301;var _0x4e7f87;var _0x1d1498;return db[_0xc8ef('0x1d')][_0xc8ef('0x4a')]({'where':_0x20d3e5[_0xc8ef('0x1f')]['where']||{},'attributes':['id',_0xc8ef('0x2a'),_0xc8ef('0x38'),_0xc8ef('0x4b'),'phone',_0xc8ef('0x39'),_0xc8ef('0x4c'),_0xc8ef('0x2b')]})[_0xc8ef('0x11')](function(_0x5ca85b){if(_0x5ca85b){_0x2229df=_0x5ca85b;_0x1d1498=_0x20d3e5['body']['interface']?_0x20d3e5[_0xc8ef('0x36')][_0xc8ef('0x2b')]:util[_0xc8ef('0x2f')](_0xc8ef('0x4d'),_0x2229df[_0xc8ef('0x2a')]);return db[_0xc8ef('0x1d')][_0xc8ef('0x4e')]({'where':{'role':'agent','online':!![],'id':{'$ne':_0x2229df['id']}}});}})[_0xc8ef('0x11')](function(_0x447d1c){if(_0x447d1c){_0x4e7f87=_0x447d1c;return require('../../config/license/util')[_0xc8ef('0x4f')]();}})[_0xc8ef('0x11')](function(_0x145697){if(_0x145697&&_0x145697[_0xc8ef('0x50')]&&_0x4e7f87>=_0x145697['agents']){throw new Error(_0xc8ef('0x51'));}})['then'](function(){if(_0x2229df){return db['UserVoiceQueueRt'][_0xc8ef('0x49')]({'where':{'membername':_0x2229df['name']},'individualHooks':!![]});}})[_0xc8ef('0x11')](function(){if(_0x2229df){return _0x2229df[_0xc8ef('0x52')]({'raw':!![]});}})['then'](function(_0x2c10f1){if(_0x2229df){if(_0x2c10f1){var _0x40e101=[];_0x3b2301=_0x2c10f1;if(_0x3b2301[_0xc8ef('0x30')]){for(var _0x4830e7=0x0;_0x4830e7<_0x3b2301[_0xc8ef('0x30')];_0x4830e7++){_0x40e101[_0xc8ef('0x33')](db['UserVoiceQueueRt'][_0xc8ef('0x53')]({'membername':_0x2229df[_0xc8ef('0x2a')],'UserId':_0x2229df['id'],'queue_name':_0x3b2301[_0x4830e7][_0xc8ef('0x2a')],'VoiceQueueId':_0x3b2301[_0x4830e7]['id'],'interface':_0x1d1498,'paused':_0x2229df[_0xc8ef('0x4c')]||![],'penalty':_0x3b2301[_0x4830e7][_0xc8ef('0x54')]||0x0}));}return BPromise['all'](_0x40e101);}}}})[_0xc8ef('0x11')](function(){if(_0x2229df){return db[_0xc8ef('0x3a')][_0xc8ef('0x1e')]({'where':{'membername':_0x2229df['name'],'exitAt':null}});}})[_0xc8ef('0x11')](function(_0x1bd7f0){if(_0x2229df){if(_0x1bd7f0&&_0x1bd7f0[_0xc8ef('0x30')]){var _0x4f67f4=[];_0x1bd7f0[_0xc8ef('0x32')](function(_0x204c41){_0x4f67f4['push'](_0x204c41['update']({'exitAt':moment()[_0xc8ef('0x2f')](_0xc8ef('0x35'))}));});return BPromise[_0xc8ef('0x48')](_0x4f67f4);}}})[_0xc8ef('0x11')](function(_0x584988){if(_0x2229df){var _0x5cbaa3=[];var _0x6b4180=[];var _0x457ca4=utils[_0xc8ef('0x55')]();var _0x734d4e={'membername':_0x2229df[_0xc8ef('0x2a')],'interface':_0x1d1498,'enterAt':moment()[_0xc8ef('0x2f')](_0xc8ef('0x35')),'role':_0x2229df[_0xc8ef('0x38')],'internal':_0x2229df['internal']};_0x457ca4['forEach'](function(_0x4a0795){_0x5cbaa3[_0xc8ef('0x33')](_[_0xc8ef('0x56')]({'channel':_0x4a0795,'type':'LOGIN','data1':_0xc8ef('0x57'),'data2':_0x1d1498},_0x734d4e));if(_0x2229df[_0xc8ef('0x4c')]){_0x6b4180[_0xc8ef('0x33')](_['merge']({'channel':_0x4a0795,'type':'PAUSE','data1':'LOGININPAUSE'},_0x734d4e));}});return db[_0xc8ef('0x3a')][_0xc8ef('0x3b')](_0x5cbaa3[_0xc8ef('0x58')](_0x6b4180),{'individualHooks':!![]});}})[_0xc8ef('0x11')](function(){if(_0x2229df){return _0x2229df[_0xc8ef('0x2d')]({'online':!![],'lastLoginAt':moment()[_0xc8ef('0x2f')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x2229df[_0xc8ef('0x4c')]||![],'mailPause':_0x2229df[_0xc8ef('0x4c')]||![],'chatPause':_0x2229df[_0xc8ef('0x4c')]||![],'faxPause':_0x2229df[_0xc8ef('0x4c')]||![],'smsPause':_0x2229df[_0xc8ef('0x4c')]||![],'openchannelPause':_0x2229df['loginInPause']||![],'pauseType':_0x2229df['loginInPause']?_0xc8ef('0x59'):null,'lastPauseAt':moment()[_0xc8ef('0x2f')](_0xc8ef('0x35')),'interface':_0x1d1498});}})[_0xc8ef('0x11')](function(_0x133392){_0x278159(_0x133392);})[_0xc8ef('0x1c')](function(_0x1d78ba){_0x20c829(_0x24159f[_0xc8ef('0x18')](0x1f4,_0x1d78ba[_0xc8ef('0x1a')]));});});};
\ No newline at end of file
+var _0x6739=['isValidChannel','channel','system','mail','chat','fax','sms','openchannel','whatsapp','set','%s%s','Pause','all','destroy','LoginUser','phone','loginInPause','count','agent','../../config/license/util','getLicense','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','UserVoiceQueue.penalty','merge','LOGIN','callysquare','LOGININPAUSE','bulkCreate','concat','lodash','util','moment','bluebird','randomstring','ioredis','../../config/logger','../../config/environment','http','redis','defaults','socket.io-emitter','./user.socket','request','then','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','limit','include','map','model','ShowUser','User','where','PauseUser','find','name','role','interface','UserVoiceQueueRt','update','MemberReport','length','format','YYYY-MM-DD\x20HH:mm:ss','getChannels','forEach','push','isNil','SIP/%s','PAUSE','body','internal','uniqueid','UnpauseUser','findOne'];(function(_0x3070dc,_0x40cf11){var _0x431489=function(_0x49bc2a){while(--_0x49bc2a){_0x3070dc['push'](_0x3070dc['shift']());}};_0x431489(++_0x40cf11);}(_0x6739,0xd3));var _0x9673=function(_0x4f36be,_0xbbf664){_0x4f36be=_0x4f36be-0x0;var _0x312579=_0x6739[_0x4f36be];return _0x312579;};'use strict';var _=require(_0x9673('0x0'));var util=require(_0x9673('0x1'));var moment=require(_0x9673('0x2'));var BPromise=require(_0x9673('0x3'));var rs=require(_0x9673('0x4'));var fs=require('fs');var Redis=require(_0x9673('0x5'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x9673('0x6'))('rpc');var config=require(_0x9673('0x7'));var jayson=require('jayson/promise');var client=jayson['client'][_0x9673('0x8')]({'port':0x232a});config[_0x9673('0x9')]=_[_0x9673('0xa')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x9673('0xb'))(new Redis(config[_0x9673('0x9')]));require(_0x9673('0xc'))['register'](socket);function respondWithRpcPromise(_0x405101,_0x1e99fd,_0x33073e){return new BPromise(function(_0x55f6a5,_0x30d538){return client[_0x9673('0xd')](_0x405101,_0x33073e)[_0x9673('0xe')](function(_0x3db27a){logger['info'](_0x9673('0xf'),_0x1e99fd,_0x9673('0x10'));logger[_0x9673('0x11')](_0x9673('0x12'),_0x1e99fd,'request\x20sent',JSON[_0x9673('0x13')](_0x3db27a));if(_0x3db27a[_0x9673('0x14')]){if(_0x3db27a['error'][_0x9673('0x15')]===0x1f4){logger[_0x9673('0x14')](_0x9673('0xf'),_0x1e99fd,_0x3db27a['error'][_0x9673('0x16')]);return _0x30d538(_0x3db27a['error'][_0x9673('0x16')]);}logger['error']('User,\x20%s,\x20%s',_0x1e99fd,_0x3db27a[_0x9673('0x14')]['message']);return _0x55f6a5(_0x3db27a[_0x9673('0x14')][_0x9673('0x16')]);}else{logger['info'](_0x9673('0xf'),_0x1e99fd,_0x9673('0x10'));_0x55f6a5(_0x3db27a[_0x9673('0x17')][_0x9673('0x16')]);}})[_0x9673('0x18')](function(_0x281a1a){logger[_0x9673('0x14')](_0x9673('0xf'),_0x1e99fd,_0x281a1a);_0x30d538(_0x281a1a);});});}exports[_0x9673('0x19')]=function(_0x9e3c82){var _0x5e0d05=this;return new Promise(function(_0x1831ab,_0xbfc9d6){return db['User'][_0x9673('0x1a')]({'raw':_0x9e3c82[_0x9673('0x1b')]?_0x9e3c82['options'][_0x9673('0x1c')]===undefined?!![]:![]:!![],'where':_0x9e3c82[_0x9673('0x1b')]?_0x9e3c82[_0x9673('0x1b')]['where']||null:null,'attributes':_0x9e3c82[_0x9673('0x1b')]?_0x9e3c82[_0x9673('0x1b')][_0x9673('0x1d')]||null:null,'limit':_0x9e3c82[_0x9673('0x1b')]?_0x9e3c82['options'][_0x9673('0x1e')]||null:null,'include':_0x9e3c82['options']?_0x9e3c82[_0x9673('0x1b')][_0x9673('0x1f')]?_[_0x9673('0x20')](_0x9e3c82[_0x9673('0x1b')][_0x9673('0x1f')],function(_0x415f9b){return{'model':db[_0x415f9b[_0x9673('0x21')]],'as':_0x415f9b['as'],'attributes':_0x415f9b[_0x9673('0x1d')],'include':_0x415f9b[_0x9673('0x1f')]?_['map'](_0x415f9b[_0x9673('0x1f')],function(_0x221b33){return{'model':db[_0x221b33['model']],'as':_0x221b33['as'],'attributes':_0x221b33['attributes'],'include':_0x221b33[_0x9673('0x1f')]?_[_0x9673('0x20')](_0x221b33[_0x9673('0x1f')],function(_0x3dba72){return{'model':db[_0x3dba72['model']],'as':_0x3dba72['as'],'attributes':_0x3dba72[_0x9673('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x25acab){logger['info'](_0x9673('0x19'),_0x9e3c82);logger[_0x9673('0x11')](_0x9673('0x19'),_0x9e3c82,JSON['stringify'](_0x25acab));_0x1831ab(_0x25acab);})[_0x9673('0x18')](function(_0x590825){logger[_0x9673('0x14')](_0x9673('0x19'),_0x590825['message'],_0x9e3c82);_0xbfc9d6(_0x5e0d05['error'](0x1f4,_0x590825[_0x9673('0x16')]));});});};exports[_0x9673('0x22')]=function(_0x12f8a7){var _0x28d3c0=this;return new Promise(function(_0x332966,_0x2f9949){return db[_0x9673('0x23')]['find']({'raw':_0x12f8a7[_0x9673('0x1b')]?_0x12f8a7[_0x9673('0x1b')][_0x9673('0x1c')]===undefined?!![]:![]:!![],'where':_0x12f8a7[_0x9673('0x1b')]?_0x12f8a7[_0x9673('0x1b')][_0x9673('0x24')]||null:null,'attributes':_0x12f8a7[_0x9673('0x1b')]?_0x12f8a7[_0x9673('0x1b')][_0x9673('0x1d')]||null:null,'include':_0x12f8a7[_0x9673('0x1b')]?_0x12f8a7['options'][_0x9673('0x1f')]?_['map'](_0x12f8a7['options'][_0x9673('0x1f')],function(_0x344c12){return{'model':db[_0x344c12[_0x9673('0x21')]],'as':_0x344c12['as'],'attributes':_0x344c12[_0x9673('0x1d')],'include':_0x344c12['include']?_[_0x9673('0x20')](_0x344c12[_0x9673('0x1f')],function(_0x37f616){return{'model':db[_0x37f616[_0x9673('0x21')]],'as':_0x37f616['as'],'attributes':_0x37f616[_0x9673('0x1d')],'include':_0x37f616[_0x9673('0x1f')]?_[_0x9673('0x20')](_0x37f616[_0x9673('0x1f')],function(_0x34b115){return{'model':db[_0x34b115['model']],'as':_0x34b115['as'],'attributes':_0x34b115[_0x9673('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x9673('0xe')](function(_0x4b67ad){logger['info'](_0x9673('0x22'),_0x12f8a7);logger['debug'](_0x9673('0x22'),_0x12f8a7,JSON[_0x9673('0x13')](_0x4b67ad));_0x332966(_0x4b67ad);})['catch'](function(_0x5634aa){logger[_0x9673('0x14')](_0x9673('0x22'),_0x5634aa[_0x9673('0x16')],_0x12f8a7);_0x2f9949(_0x28d3c0[_0x9673('0x14')](0x1f4,_0x5634aa[_0x9673('0x16')]));});});};exports[_0x9673('0x25')]=function(_0x8b39a0){var _0x393f83=this;return new Promise(function(_0x168169,_0x5c6395){var _0x3d38aa;return db[_0x9673('0x23')][_0x9673('0x26')]({'where':_0x8b39a0[_0x9673('0x1b')][_0x9673('0x24')]||{},'attributes':['id',_0x9673('0x27'),_0x9673('0x28'),'internal',_0x9673('0x29')]})[_0x9673('0xe')](function(_0x206938){if(_0x206938){_0x3d38aa=_0x206938;return db[_0x9673('0x2a')][_0x9673('0x2b')]({'paused':0x1},{'where':{'UserId':_0x3d38aa['id']},'individualHooks':!![]});}})['then'](function(){if(_0x3d38aa){return db[_0x9673('0x2c')]['findAll']({'where':{'membername':_0x3d38aa[_0x9673('0x27')],'type':'PAUSE','exitAt':null}});}})[_0x9673('0xe')](function(_0x4026e9){if(_0x3d38aa){if(_0x4026e9&&_0x4026e9[_0x9673('0x2d')]){var _0x437f84=moment()[_0x9673('0x2e')](_0x9673('0x2f'));for(var _0x1646f2=0x0,_0xd5af74=_0x4026e9['length'];_0x1646f2<_0xd5af74;_0x1646f2++){_0x4026e9[_0x1646f2]['updateAttributes']({'exitAt':_0x437f84});}}}})['then'](function(){if(_0x3d38aa){var _0x4a80c3=[];var _0x4050ab=utils[_0x9673('0x30')]();_0x4050ab[_0x9673('0x31')](function(_0x38264d){_0x4a80c3[_0x9673('0x32')]({'channel':_0x38264d,'membername':_0x3d38aa['name'],'interface':_[_0x9673('0x33')](_0x3d38aa[_0x9673('0x29')])?util['format'](_0x9673('0x34'),_0x3d38aa['name']):_0x3d38aa['interface'],'type':_0x9673('0x35'),'enterAt':moment()[_0x9673('0x2e')](_0x9673('0x2f')),'data1':_0x8b39a0[_0x9673('0x36')]['type']||'DEFAULT\x20PAUSE','role':_0x3d38aa[_0x9673('0x28')],'internal':_0x3d38aa[_0x9673('0x37')],'uniqueid':_0x8b39a0[_0x9673('0x36')][_0x9673('0x38')]||null});});return db[_0x9673('0x2c')]['bulkCreate'](_0x4a80c3,{'individualHooks':!![]});}})[_0x9673('0xe')](function(){if(_0x3d38aa){return _0x3d38aa[_0x9673('0x2b')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x8b39a0[_0x9673('0x36')]['type']||'DEFAULT\x20PAUSE','lastPauseAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss')});}})[_0x9673('0xe')](function(_0x36bf41){_0x168169(_0x36bf41);})[_0x9673('0x18')](function(_0x59f14a){_0x5c6395(_0x393f83[_0x9673('0x14')](0x1f4,_0x59f14a[_0x9673('0x16')]));});});};exports[_0x9673('0x39')]=function(_0x48cc16){var _0x482732=this;return new Promise(function(_0x457e1f,_0x4343a5){var _0x2f7041;return db['User'][_0x9673('0x3a')]({'where':_0x48cc16[_0x9673('0x1b')][_0x9673('0x24')]||{},'attributes':['id',_0x9673('0x27')]})['then'](function(_0x480462){if(_0x480462){_0x2f7041=_0x480462;if(_0x48cc16[_0x9673('0x36')]['channel']&&!utils[_0x9673('0x3b')](_0x48cc16[_0x9673('0x36')][_0x9673('0x3c')])){throw new Error('Unknown\x20channel');}switch(_0x48cc16[_0x9673('0x36')]['channel']){case'voice':return db[_0x9673('0x2a')][_0x9673('0x2b')]({'paused':0x0},{'where':{'UserId':_0x2f7041['id']}})[_0x9673('0xe')](function(){return db[_0x9673('0x2c')]['find']({'where':{'channel':_0x48cc16[_0x9673('0x36')]['channel'],'membername':_0x2f7041[_0x9673('0x27')],'type':_0x9673('0x35'),'exitAt':null}});})[_0x9673('0xe')](function(_0xd14321){if(_0xd14321){return _0xd14321['update']({'exitAt':moment()[_0x9673('0x2e')](_0x9673('0x2f')),'data2':_0x9673('0x3d')},{'individualHooks':!![]});}return null;})['then'](function(){return _0x2f7041[_0x9673('0x2b')]({'voicePause':![]});});case _0x9673('0x3e'):case _0x9673('0x3f'):case _0x9673('0x40'):case _0x9673('0x41'):case _0x9673('0x42'):case _0x9673('0x43'):return db[_0x9673('0x2c')][_0x9673('0x26')]({'where':{'channel':_0x48cc16[_0x9673('0x36')][_0x9673('0x3c')],'membername':_0x2f7041[_0x9673('0x27')],'type':'PAUSE','exitAt':null}})[_0x9673('0xe')](function(_0x268baf){return _0x268baf[_0x9673('0x2b')]({'exitAt':moment()[_0x9673('0x2e')](_0x9673('0x2f')),'data2':'system'},{'individualHooks':!![]});})['then'](function(){var _0x4b99d3={};_[_0x9673('0x44')](_0x4b99d3,util['format'](_0x9673('0x45'),_0x48cc16[_0x9673('0x36')][_0x9673('0x3c')],_0x9673('0x46')),![]);return _0x2f7041[_0x9673('0x2b')](_0x4b99d3);});default:return db[_0x9673('0x2a')][_0x9673('0x2b')]({'paused':0x0},{'where':{'UserId':_0x2f7041['id']}})[_0x9673('0xe')](function(){return db[_0x9673('0x2c')][_0x9673('0x1a')]({'where':{'membername':_0x2f7041[_0x9673('0x27')],'type':_0x9673('0x35'),'exitAt':null}});})[_0x9673('0xe')](function(_0x19fda9){var _0xac0d77=[];_0x19fda9[_0x9673('0x31')](function(_0x587251){_0xac0d77['push'](_0x587251[_0x9673('0x2b')]({'exitAt':moment()['format'](_0x9673('0x2f')),'data2':_0x9673('0x3d')}));});return BPromise[_0x9673('0x47')](_0xac0d77);})['then'](function(){return _0x2f7041['update']({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0x9673('0xe')](function(_0x1bad82){_0x457e1f(_0x1bad82);})[_0x9673('0x18')](function(_0x1929a1){_0x4343a5(_0x482732[_0x9673('0x14')](0x1f4,_0x1929a1[_0x9673('0x16')]));});});};exports['LogoutUser']=function(_0x436ead){var _0x34b104=this;return new Promise(function(_0xb2f6c2,_0x109f12){var _0x1aaaeb;return db['User'][_0x9673('0x3a')]({'where':_0x436ead['options'][_0x9673('0x24')]||{},'attributes':['id',_0x9673('0x27')]})['then'](function(_0x2d5580){if(_0x2d5580){_0x1aaaeb=_0x2d5580;return db['UserVoiceQueueRt'][_0x9673('0x48')]({'where':{'membername':_0x1aaaeb[_0x9673('0x27')]},'individualHooks':!![]});}})[_0x9673('0xe')](function(){if(_0x1aaaeb){return db[_0x9673('0x2c')]['findAll']({'where':{'membername':_0x1aaaeb[_0x9673('0x27')],'exitAt':null}});}})['then'](function(_0x44cab1){if(_0x1aaaeb){if(_0x44cab1&&_0x44cab1['length']){var _0x6dc687=[];_0x44cab1[_0x9673('0x31')](function(_0xbd2d40){_0x6dc687[_0x9673('0x32')](_0xbd2d40[_0x9673('0x2b')]({'exitAt':moment()['format'](_0x9673('0x2f'))}));});return BPromise[_0x9673('0x47')](_0x6dc687);}}})['then'](function(){if(_0x1aaaeb){return _0x1aaaeb[_0x9673('0x2b')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0x9673('0xe')](function(_0x193f1b){_0xb2f6c2(_0x193f1b);})[_0x9673('0x18')](function(_0x1cd1fb){_0x109f12(_0x34b104[_0x9673('0x14')](0x1f4,_0x1cd1fb[_0x9673('0x16')]));});});};exports[_0x9673('0x49')]=function(_0x51c25a){var _0x41135f=this;return new Promise(function(_0x3b7f3f,_0x1a7ff5){var _0x7a9c52;var _0x3aa063;var _0x3b80d9;var _0x229fcf;return db[_0x9673('0x23')]['findOne']({'where':_0x51c25a[_0x9673('0x1b')]['where']||{},'attributes':['id',_0x9673('0x27'),_0x9673('0x28'),'mobile',_0x9673('0x4a'),_0x9673('0x37'),_0x9673('0x4b'),'interface']})[_0x9673('0xe')](function(_0x574a2d){if(_0x574a2d){_0x7a9c52=_0x574a2d;_0x229fcf=_0x51c25a[_0x9673('0x36')][_0x9673('0x29')]?_0x51c25a[_0x9673('0x36')][_0x9673('0x29')]:util[_0x9673('0x2e')](_0x9673('0x34'),_0x7a9c52[_0x9673('0x27')]);return db[_0x9673('0x23')][_0x9673('0x4c')]({'where':{'role':_0x9673('0x4d'),'online':!![],'id':{'$ne':_0x7a9c52['id']}}});}})[_0x9673('0xe')](function(_0x4c241f){if(_0x4c241f){_0x3b80d9=_0x4c241f;return require(_0x9673('0x4e'))[_0x9673('0x4f')]();}})[_0x9673('0xe')](function(_0x18a1e7){if(_0x18a1e7&&_0x18a1e7['agents']&&_0x3b80d9>=_0x18a1e7['agents']){throw new Error(_0x9673('0x50'));}})[_0x9673('0xe')](function(){if(_0x7a9c52){return db[_0x9673('0x2a')][_0x9673('0x48')]({'where':{'membername':_0x7a9c52[_0x9673('0x27')]},'individualHooks':!![]});}})[_0x9673('0xe')](function(){if(_0x7a9c52){return _0x7a9c52[_0x9673('0x51')]({'raw':!![]});}})[_0x9673('0xe')](function(_0x233bfc){if(_0x7a9c52){if(_0x233bfc){var _0x465887=[];_0x3aa063=_0x233bfc;if(_0x3aa063[_0x9673('0x2d')]){for(var _0x26e777=0x0;_0x26e777<_0x3aa063[_0x9673('0x2d')];_0x26e777++){_0x465887[_0x9673('0x32')](db['UserVoiceQueueRt'][_0x9673('0x52')]({'membername':_0x7a9c52[_0x9673('0x27')],'UserId':_0x7a9c52['id'],'queue_name':_0x3aa063[_0x26e777]['name'],'VoiceQueueId':_0x3aa063[_0x26e777]['id'],'interface':_0x229fcf,'paused':_0x7a9c52[_0x9673('0x4b')]||![],'penalty':_0x3aa063[_0x26e777][_0x9673('0x53')]||0x0}));}return BPromise[_0x9673('0x47')](_0x465887);}}}})['then'](function(){if(_0x7a9c52){return db['MemberReport'][_0x9673('0x1a')]({'where':{'membername':_0x7a9c52[_0x9673('0x27')],'exitAt':null}});}})[_0x9673('0xe')](function(_0x186d7f){if(_0x7a9c52){if(_0x186d7f&&_0x186d7f[_0x9673('0x2d')]){var _0x3c3a76=[];_0x186d7f[_0x9673('0x31')](function(_0x4adb7a){_0x3c3a76[_0x9673('0x32')](_0x4adb7a['update']({'exitAt':moment()['format'](_0x9673('0x2f'))}));});return BPromise[_0x9673('0x47')](_0x3c3a76);}}})[_0x9673('0xe')](function(_0x4a25a3){if(_0x7a9c52){var _0x1ffdc2=[];var _0x300cd7=[];var _0x4d1821=utils[_0x9673('0x30')]();var _0x2b1869={'membername':_0x7a9c52[_0x9673('0x27')],'interface':_0x229fcf,'enterAt':moment()[_0x9673('0x2e')](_0x9673('0x2f')),'role':_0x7a9c52[_0x9673('0x28')],'internal':_0x7a9c52[_0x9673('0x37')]};_0x4d1821[_0x9673('0x31')](function(_0x9e4b6c){_0x1ffdc2[_0x9673('0x32')](_[_0x9673('0x54')]({'channel':_0x9e4b6c,'type':_0x9673('0x55'),'data1':_0x9673('0x56'),'data2':_0x229fcf},_0x2b1869));if(_0x7a9c52[_0x9673('0x4b')]){_0x300cd7[_0x9673('0x32')](_[_0x9673('0x54')]({'channel':_0x9e4b6c,'type':_0x9673('0x35'),'data1':_0x9673('0x57')},_0x2b1869));}});return db['MemberReport'][_0x9673('0x58')](_0x1ffdc2[_0x9673('0x59')](_0x300cd7),{'individualHooks':!![]});}})[_0x9673('0xe')](function(){if(_0x7a9c52){return _0x7a9c52['update']({'online':!![],'lastLoginAt':moment()[_0x9673('0x2e')](_0x9673('0x2f')),'voicePause':_0x7a9c52[_0x9673('0x4b')]||![],'mailPause':_0x7a9c52[_0x9673('0x4b')]||![],'chatPause':_0x7a9c52['loginInPause']||![],'faxPause':_0x7a9c52[_0x9673('0x4b')]||![],'smsPause':_0x7a9c52[_0x9673('0x4b')]||![],'openchannelPause':_0x7a9c52[_0x9673('0x4b')]||![],'pauseType':_0x7a9c52[_0x9673('0x4b')]?_0x9673('0x57'):null,'lastPauseAt':moment()['format'](_0x9673('0x2f')),'interface':_0x229fcf});}})[_0x9673('0xe')](function(_0x3cabbc){_0x3b7f3f(_0x3cabbc);})['catch'](function(_0x22a1c0){_0x1a7ff5(_0x41135f[_0x9673('0x14')](0x1f4,_0x22a1c0['message']));});});};
\ No newline at end of file