Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / api / user / user.rpc.js
index d8f9584..8f2bc70 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xcc4a=['mobile','loginInPause','SIP/%s','agent','../../config/license/util','getLicense','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','getChannels','merge','LOGIN','LOGININPAUSE','concat','lodash','util','moment','randomstring','ioredis','../../mysqldb','rpc','../../config/environment','jayson/promise','client','http','redis','socket.io-emitter','./user.socket','request','info','User,\x20%s,\x20%s','request\x20sent','User,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetUser','findAll','options','raw','where','attributes','limit','include','map','model','then','User','find','ShowUser','internal','interface','update','MemberReport','PAUSE','format','YYYY-MM-DD\x20HH:mm:ss','length','forEach','push','name','body','type','role','bulkCreate','DEFAULT\x20PAUSE','UnpauseUser','findOne','isValidChannel','Unknown\x20channel','channel','voice','UserVoiceQueueRt','system','mail','chat','fax','sms','set','Pause','all','LogoutUser','LoginUser'];(function(_0x31680b,_0x3a82fe){var _0x28bd5c=function(_0x39f8d0){while(--_0x39f8d0){_0x31680b['push'](_0x31680b['shift']());}};_0x28bd5c(++_0x3a82fe);}(_0xcc4a,0xba));var _0xacc4=function(_0x3e665b,_0xc6e475){_0x3e665b=_0x3e665b-0x0;var _0x261ede=_0xcc4a[_0x3e665b];return _0x261ede;};'use strict';var _=require(_0xacc4('0x0'));var util=require(_0xacc4('0x1'));var moment=require(_0xacc4('0x2'));var BPromise=require('bluebird');var rs=require(_0xacc4('0x3'));var fs=require('fs');var Redis=require(_0xacc4('0x4'));var db=require(_0xacc4('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0xacc4('0x6'));var config=require(_0xacc4('0x7'));var jayson=require(_0xacc4('0x8'));var client=jayson[_0xacc4('0x9')][_0xacc4('0xa')]({'port':0x232a});config[_0xacc4('0xb')]=_['defaults'](config[_0xacc4('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0xacc4('0xc'))(new Redis(config[_0xacc4('0xb')]));require(_0xacc4('0xd'))['register'](socket);function respondWithRpcPromise(_0x557fd8,_0x1a1960,_0x333336){return new BPromise(function(_0x5dd9cb,_0x5b2c75){return client[_0xacc4('0xe')](_0x557fd8,_0x333336)['then'](function(_0x15e6d6){logger[_0xacc4('0xf')](_0xacc4('0x10'),_0x1a1960,_0xacc4('0x11'));logger['debug'](_0xacc4('0x12'),_0x1a1960,_0xacc4('0x11'),JSON[_0xacc4('0x13')](_0x15e6d6));if(_0x15e6d6[_0xacc4('0x14')]){if(_0x15e6d6[_0xacc4('0x14')][_0xacc4('0x15')]===0x1f4){logger['error'](_0xacc4('0x10'),_0x1a1960,_0x15e6d6[_0xacc4('0x14')][_0xacc4('0x16')]);return _0x5b2c75(_0x15e6d6[_0xacc4('0x14')][_0xacc4('0x16')]);}logger[_0xacc4('0x14')]('User,\x20%s,\x20%s',_0x1a1960,_0x15e6d6[_0xacc4('0x14')][_0xacc4('0x16')]);return _0x5dd9cb(_0x15e6d6[_0xacc4('0x14')][_0xacc4('0x16')]);}else{logger[_0xacc4('0xf')](_0xacc4('0x10'),_0x1a1960,_0xacc4('0x11'));_0x5dd9cb(_0x15e6d6[_0xacc4('0x17')][_0xacc4('0x16')]);}})[_0xacc4('0x18')](function(_0x542596){logger[_0xacc4('0x14')](_0xacc4('0x10'),_0x1a1960,_0x542596);_0x5b2c75(_0x542596);});});}exports[_0xacc4('0x19')]=function(_0x5893c3){var _0x241720=this;return new Promise(function(_0x5d95c1,_0x470ec9){return db['User'][_0xacc4('0x1a')]({'raw':_0x5893c3[_0xacc4('0x1b')]?_0x5893c3[_0xacc4('0x1b')][_0xacc4('0x1c')]===undefined?!![]:![]:!![],'where':_0x5893c3[_0xacc4('0x1b')]?_0x5893c3['options'][_0xacc4('0x1d')]||null:null,'attributes':_0x5893c3[_0xacc4('0x1b')]?_0x5893c3[_0xacc4('0x1b')][_0xacc4('0x1e')]||null:null,'limit':_0x5893c3[_0xacc4('0x1b')]?_0x5893c3['options'][_0xacc4('0x1f')]||null:null,'include':_0x5893c3['options']?_0x5893c3['options'][_0xacc4('0x20')]?_[_0xacc4('0x21')](_0x5893c3[_0xacc4('0x1b')][_0xacc4('0x20')],function(_0x940e14){return{'model':db[_0x940e14['model']],'as':_0x940e14['as'],'attributes':_0x940e14['attributes'],'include':_0x940e14[_0xacc4('0x20')]?_['map'](_0x940e14['include'],function(_0x45a297){return{'model':db[_0x45a297[_0xacc4('0x22')]],'as':_0x45a297['as'],'attributes':_0x45a297[_0xacc4('0x1e')],'include':_0x45a297[_0xacc4('0x20')]?_['map'](_0x45a297[_0xacc4('0x20')],function(_0x2cbead){return{'model':db[_0x2cbead[_0xacc4('0x22')]],'as':_0x2cbead['as'],'attributes':_0x2cbead['attributes']};}):[]};}):[]};}):[]:[]})[_0xacc4('0x23')](function(_0x403442){logger[_0xacc4('0xf')](_0xacc4('0x19'),_0x5893c3);logger['debug'](_0xacc4('0x19'),_0x5893c3,JSON[_0xacc4('0x13')](_0x403442));_0x5d95c1(_0x403442);})[_0xacc4('0x18')](function(_0x249ff0){logger[_0xacc4('0x14')](_0xacc4('0x19'),_0x249ff0[_0xacc4('0x16')],_0x5893c3);_0x470ec9(_0x241720[_0xacc4('0x14')](0x1f4,_0x249ff0[_0xacc4('0x16')]));});});};exports['ShowUser']=function(_0x262ff2){var _0x541784=this;return new Promise(function(_0x570d3c,_0x116e53){return db[_0xacc4('0x24')][_0xacc4('0x25')]({'raw':_0x262ff2[_0xacc4('0x1b')]?_0x262ff2['options'][_0xacc4('0x1c')]===undefined?!![]:![]:!![],'where':_0x262ff2[_0xacc4('0x1b')]?_0x262ff2[_0xacc4('0x1b')]['where']||null:null,'attributes':_0x262ff2[_0xacc4('0x1b')]?_0x262ff2[_0xacc4('0x1b')][_0xacc4('0x1e')]||null:null,'include':_0x262ff2[_0xacc4('0x1b')]?_0x262ff2[_0xacc4('0x1b')][_0xacc4('0x20')]?_[_0xacc4('0x21')](_0x262ff2['options'][_0xacc4('0x20')],function(_0x32bdec){return{'model':db[_0x32bdec[_0xacc4('0x22')]],'as':_0x32bdec['as'],'attributes':_0x32bdec[_0xacc4('0x1e')],'include':_0x32bdec[_0xacc4('0x20')]?_[_0xacc4('0x21')](_0x32bdec[_0xacc4('0x20')],function(_0x33b502){return{'model':db[_0x33b502[_0xacc4('0x22')]],'as':_0x33b502['as'],'attributes':_0x33b502[_0xacc4('0x1e')],'include':_0x33b502[_0xacc4('0x20')]?_[_0xacc4('0x21')](_0x33b502[_0xacc4('0x20')],function(_0xf0ba6e){return{'model':db[_0xf0ba6e[_0xacc4('0x22')]],'as':_0xf0ba6e['as'],'attributes':_0xf0ba6e['attributes']};}):[]};}):[]};}):[]:[]})[_0xacc4('0x23')](function(_0x5a0233){logger[_0xacc4('0xf')]('ShowUser',_0x262ff2);logger['debug'](_0xacc4('0x26'),_0x262ff2,JSON[_0xacc4('0x13')](_0x5a0233));_0x570d3c(_0x5a0233);})[_0xacc4('0x18')](function(_0x38cb64){logger[_0xacc4('0x14')](_0xacc4('0x26'),_0x38cb64[_0xacc4('0x16')],_0x262ff2);_0x116e53(_0x541784['error'](0x1f4,_0x38cb64['message']));});});};exports['PauseUser']=function(_0x4ae04d){var _0x428219=this;return new Promise(function(_0x51da1a,_0x3003a7){var _0x29badf;return db[_0xacc4('0x24')][_0xacc4('0x25')]({'where':_0x4ae04d[_0xacc4('0x1b')][_0xacc4('0x1d')]||{},'attributes':['id','name','role',_0xacc4('0x27'),_0xacc4('0x28')]})[_0xacc4('0x23')](function(_0x1b6701){if(_0x1b6701){_0x29badf=_0x1b6701;return db['UserVoiceQueueRt'][_0xacc4('0x29')]({'paused':0x1},{'where':{'UserId':_0x29badf['id']},'individualHooks':!![]});}})[_0xacc4('0x23')](function(){if(_0x29badf){return db[_0xacc4('0x2a')][_0xacc4('0x1a')]({'where':{'membername':_0x29badf['name'],'type':_0xacc4('0x2b'),'exitAt':null}});}})[_0xacc4('0x23')](function(_0x55e2b7){if(_0x29badf){if(_0x55e2b7&&_0x55e2b7['length']){var _0x3b2ed7=moment()[_0xacc4('0x2c')](_0xacc4('0x2d'));for(var _0x55dec3=0x0,_0x4aceb9=_0x55e2b7[_0xacc4('0x2e')];_0x55dec3<_0x4aceb9;_0x55dec3++){_0x55e2b7[_0x55dec3]['updateAttributes']({'exitAt':_0x3b2ed7});}}}})[_0xacc4('0x23')](function(){if(_0x29badf){var _0x2fa68a=[];var _0x176b1e=utils['getChannels']();_0x176b1e[_0xacc4('0x2f')](function(_0x15d644){_0x2fa68a[_0xacc4('0x30')]({'channel':_0x15d644,'membername':_0x29badf['name'],'interface':_['isNil'](_0x29badf[_0xacc4('0x28')])?util[_0xacc4('0x2c')]('SIP/%s',_0x29badf[_0xacc4('0x31')]):_0x29badf[_0xacc4('0x28')],'type':_0xacc4('0x2b'),'enterAt':moment()['format'](_0xacc4('0x2d')),'data1':_0x4ae04d[_0xacc4('0x32')][_0xacc4('0x33')]||'DEFAULT\x20PAUSE','role':_0x29badf[_0xacc4('0x34')],'internal':_0x29badf[_0xacc4('0x27')],'uniqueid':_0x4ae04d[_0xacc4('0x32')]['uniqueid']||null});});return db[_0xacc4('0x2a')][_0xacc4('0x35')](_0x2fa68a,{'individualHooks':!![]});}})['then'](function(){if(_0x29badf){return _0x29badf['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'pauseType':_0x4ae04d[_0xacc4('0x32')][_0xacc4('0x33')]||_0xacc4('0x36'),'lastPauseAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d'))});}})[_0xacc4('0x23')](function(_0x54ce37){_0x51da1a(_0x54ce37);})['catch'](function(_0x3b07db){_0x3003a7(_0x428219[_0xacc4('0x14')](0x1f4,_0x3b07db[_0xacc4('0x16')]));});});};exports[_0xacc4('0x37')]=function(_0x126656){var _0x1e7ce4=this;return new Promise(function(_0xf6bbf1,_0x4f4cb5){var _0x2e6432;return db[_0xacc4('0x24')][_0xacc4('0x38')]({'where':_0x126656[_0xacc4('0x1b')][_0xacc4('0x1d')]||{},'attributes':['id',_0xacc4('0x31')]})[_0xacc4('0x23')](function(_0x2ebab6){if(_0x2ebab6){_0x2e6432=_0x2ebab6;if(_0x126656[_0xacc4('0x32')]['channel']&&!utils[_0xacc4('0x39')](_0x126656[_0xacc4('0x32')]['channel'])){throw new Error(_0xacc4('0x3a'));}switch(_0x126656[_0xacc4('0x32')][_0xacc4('0x3b')]){case _0xacc4('0x3c'):return db[_0xacc4('0x3d')][_0xacc4('0x29')]({'paused':0x0},{'where':{'UserId':_0x2e6432['id']}})[_0xacc4('0x23')](function(){return db[_0xacc4('0x2a')][_0xacc4('0x25')]({'where':{'channel':_0x126656[_0xacc4('0x32')][_0xacc4('0x3b')],'membername':_0x2e6432['name'],'type':_0xacc4('0x2b'),'exitAt':null}});})[_0xacc4('0x23')](function(_0x46095d){if(_0x46095d){return _0x46095d['update']({'exitAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d')),'data2':_0xacc4('0x3e')},{'individualHooks':!![]});}return null;})[_0xacc4('0x23')](function(){return _0x2e6432[_0xacc4('0x29')]({'voicePause':![]});});case _0xacc4('0x3f'):case _0xacc4('0x40'):case _0xacc4('0x41'):case _0xacc4('0x42'):case'openchannel':return db[_0xacc4('0x2a')][_0xacc4('0x25')]({'where':{'channel':_0x126656[_0xacc4('0x32')]['channel'],'membername':_0x2e6432[_0xacc4('0x31')],'type':_0xacc4('0x2b'),'exitAt':null}})[_0xacc4('0x23')](function(_0x2ae5a4){return _0x2ae5a4['update']({'exitAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d')),'data2':_0xacc4('0x3e')},{'individualHooks':!![]});})[_0xacc4('0x23')](function(){var _0x13be0e={};_[_0xacc4('0x43')](_0x13be0e,util[_0xacc4('0x2c')]('%s%s',_0x126656['body'][_0xacc4('0x3b')],_0xacc4('0x44')),![]);return _0x2e6432[_0xacc4('0x29')](_0x13be0e);});default:return db[_0xacc4('0x3d')][_0xacc4('0x29')]({'paused':0x0},{'where':{'UserId':_0x2e6432['id']}})[_0xacc4('0x23')](function(){return db[_0xacc4('0x2a')][_0xacc4('0x1a')]({'where':{'membername':_0x2e6432[_0xacc4('0x31')],'type':_0xacc4('0x2b'),'exitAt':null}});})[_0xacc4('0x23')](function(_0x17d9dc){var _0x83a2ea=[];_0x17d9dc[_0xacc4('0x2f')](function(_0x192ed2){_0x83a2ea[_0xacc4('0x30')](_0x192ed2[_0xacc4('0x29')]({'exitAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d')),'data2':_0xacc4('0x3e')}));});return BPromise[_0xacc4('0x45')](_0x83a2ea);})['then'](function(){return _0x2e6432[_0xacc4('0x29')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});});}}})['then'](function(_0x28bbcc){_0xf6bbf1(_0x28bbcc);})[_0xacc4('0x18')](function(_0x2bb362){_0x4f4cb5(_0x1e7ce4[_0xacc4('0x14')](0x1f4,_0x2bb362[_0xacc4('0x16')]));});});};exports[_0xacc4('0x46')]=function(_0x41e0b2){var _0x5b35bd=this;return new Promise(function(_0x2dd555,_0x5ee387){var _0xd0ecb3;return db[_0xacc4('0x24')][_0xacc4('0x38')]({'where':_0x41e0b2[_0xacc4('0x1b')][_0xacc4('0x1d')]||{},'attributes':['id',_0xacc4('0x31')]})[_0xacc4('0x23')](function(_0x3bd13e){if(_0x3bd13e){_0xd0ecb3=_0x3bd13e;return db[_0xacc4('0x3d')]['destroy']({'where':{'membername':_0xd0ecb3[_0xacc4('0x31')]},'individualHooks':!![]});}})['then'](function(){if(_0xd0ecb3){return db[_0xacc4('0x2a')][_0xacc4('0x1a')]({'where':{'membername':_0xd0ecb3[_0xacc4('0x31')],'exitAt':null}});}})[_0xacc4('0x23')](function(_0x2a505b){if(_0xd0ecb3){if(_0x2a505b&&_0x2a505b['length']){var _0x5cff7a=[];_0x2a505b['forEach'](function(_0x4ea7d4){_0x5cff7a[_0xacc4('0x30')](_0x4ea7d4[_0xacc4('0x29')]({'exitAt':moment()[_0xacc4('0x2c')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0xacc4('0x45')](_0x5cff7a);}}})[_0xacc4('0x23')](function(){if(_0xd0ecb3){return _0xd0ecb3[_0xacc4('0x29')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xacc4('0x23')](function(_0x5c0c01){_0x2dd555(_0x5c0c01);})[_0xacc4('0x18')](function(_0x127eae){_0x5ee387(_0x5b35bd[_0xacc4('0x14')](0x1f4,_0x127eae[_0xacc4('0x16')]));});});};exports[_0xacc4('0x47')]=function(_0xd650f2){var _0x3f5b47=this;return new Promise(function(_0x40b1e0,_0x44cea7){var _0x2754b9;var _0x222b9e;var _0x2150b3;var _0xbec5ac;return db['User'][_0xacc4('0x38')]({'where':_0xd650f2[_0xacc4('0x1b')][_0xacc4('0x1d')]||{},'attributes':['id',_0xacc4('0x31'),'role',_0xacc4('0x48'),'phone','internal',_0xacc4('0x49'),_0xacc4('0x28')]})[_0xacc4('0x23')](function(_0x55ecbe){if(_0x55ecbe){_0x2754b9=_0x55ecbe;_0xbec5ac=_0xd650f2[_0xacc4('0x32')]['interface']?_0xd650f2['body'][_0xacc4('0x28')]:util['format'](_0xacc4('0x4a'),_0x2754b9['name']);return db['User']['count']({'where':{'role':_0xacc4('0x4b'),'online':!![],'id':{'$ne':_0x2754b9['id']}}});}})[_0xacc4('0x23')](function(_0x59c2cc){if(_0x59c2cc){_0x2150b3=_0x59c2cc;return require(_0xacc4('0x4c'))[_0xacc4('0x4d')]();}})[_0xacc4('0x23')](function(_0x4d4a5b){if(_0x4d4a5b&&_0x4d4a5b['agents']&&_0x2150b3>=_0x4d4a5b['agents']){throw new Error(_0xacc4('0x4e'));}})[_0xacc4('0x23')](function(){if(_0x2754b9){return db[_0xacc4('0x3d')]['destroy']({'where':{'membername':_0x2754b9['name']},'individualHooks':!![]});}})[_0xacc4('0x23')](function(){if(_0x2754b9){return _0x2754b9[_0xacc4('0x4f')]({'raw':!![]});}})[_0xacc4('0x23')](function(_0x5a4993){if(_0x2754b9){if(_0x5a4993){var _0x533726=[];_0x222b9e=_0x5a4993;if(_0x222b9e[_0xacc4('0x2e')]){for(var _0x1c172f=0x0;_0x1c172f<_0x222b9e[_0xacc4('0x2e')];_0x1c172f++){_0x533726[_0xacc4('0x30')](db[_0xacc4('0x3d')][_0xacc4('0x50')]({'membername':_0x2754b9[_0xacc4('0x31')],'UserId':_0x2754b9['id'],'queue_name':_0x222b9e[_0x1c172f][_0xacc4('0x31')],'VoiceQueueId':_0x222b9e[_0x1c172f]['id'],'interface':_0xbec5ac,'paused':_0x2754b9[_0xacc4('0x49')]||![],'penalty':_0x222b9e[_0x1c172f]['UserVoiceQueue.penalty']||0x0}));}return BPromise['all'](_0x533726);}}}})[_0xacc4('0x23')](function(){if(_0x2754b9){return db[_0xacc4('0x2a')]['findAll']({'where':{'membername':_0x2754b9['name'],'exitAt':null}});}})[_0xacc4('0x23')](function(_0x1f6c3f){if(_0x2754b9){if(_0x1f6c3f&&_0x1f6c3f[_0xacc4('0x2e')]){var _0xcef1e8=[];_0x1f6c3f['forEach'](function(_0xf45853){_0xcef1e8[_0xacc4('0x30')](_0xf45853[_0xacc4('0x29')]({'exitAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d'))}));});return BPromise[_0xacc4('0x45')](_0xcef1e8);}}})[_0xacc4('0x23')](function(_0x1a8087){if(_0x2754b9){var _0x4d63f3=[];var _0x202629=[];var _0x2ab12c=utils[_0xacc4('0x51')]();var _0xa46cf3={'membername':_0x2754b9[_0xacc4('0x31')],'interface':_0xbec5ac,'enterAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d')),'role':_0x2754b9[_0xacc4('0x34')],'internal':_0x2754b9[_0xacc4('0x27')]};_0x2ab12c['forEach'](function(_0x13f5af){_0x4d63f3['push'](_[_0xacc4('0x52')]({'channel':_0x13f5af,'type':_0xacc4('0x53'),'data1':'callysquare','data2':_0xbec5ac},_0xa46cf3));if(_0x2754b9[_0xacc4('0x49')]){_0x202629[_0xacc4('0x30')](_[_0xacc4('0x52')]({'channel':_0x13f5af,'type':_0xacc4('0x2b'),'data1':_0xacc4('0x54')},_0xa46cf3));}});return db[_0xacc4('0x2a')][_0xacc4('0x35')](_0x4d63f3[_0xacc4('0x55')](_0x202629),{'individualHooks':!![]});}})[_0xacc4('0x23')](function(){if(_0x2754b9){return _0x2754b9[_0xacc4('0x29')]({'online':!![],'lastLoginAt':moment()['format'](_0xacc4('0x2d')),'voicePause':_0x2754b9[_0xacc4('0x49')]||![],'mailPause':_0x2754b9[_0xacc4('0x49')]||![],'chatPause':_0x2754b9[_0xacc4('0x49')]||![],'faxPause':_0x2754b9[_0xacc4('0x49')]||![],'smsPause':_0x2754b9[_0xacc4('0x49')]||![],'openchannelPause':_0x2754b9['loginInPause']||![],'pauseType':_0x2754b9[_0xacc4('0x49')]?_0xacc4('0x54'):null,'lastPauseAt':moment()[_0xacc4('0x2c')](_0xacc4('0x2d')),'interface':_0xbec5ac});}})['then'](function(_0x4894a7){_0x40b1e0(_0x4894a7);})[_0xacc4('0x18')](function(_0x1bf576){_0x44cea7(_0x3f5b47['error'](0x1f4,_0x1bf576[_0xacc4('0x16')]));});});};
\ No newline at end of file
+var _0x60f7=['error','message','User,\x20%s,\x20%s','result','catch','findAll','options','raw','where','attributes','limit','include','map','model','GetUser','stringify','ShowUser','User','find','PauseUser','name','role','UserVoiceQueueRt','update','MemberReport','PAUSE','format','YYYY-MM-DD\x20HH:mm:ss','length','updateAttributes','forEach','push','isNil','interface','body','type','internal','uniqueid','bulkCreate','UnpauseUser','findOne','channel','isValidChannel','Unknown\x20channel','voice','system','mail','chat','fax','sms','openchannel','set','all','LogoutUser','LoginUser','mobile','SIP/%s','count','agent','../../config/license/util','getLicense','agents','destroy','upsert','loginInPause','UserVoiceQueue.penalty','getChannels','merge','LOGIN','callysquare','LOGININPAUSE','concat','lodash','util','moment','bluebird','randomstring','ioredis','../../config/logger','rpc','../../config/environment','client','http','redis','localhost','./user.socket','register','then','info','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s'];(function(_0x3fbe61,_0x6b5852){var _0xad6457=function(_0x2dc6a7){while(--_0x2dc6a7){_0x3fbe61['push'](_0x3fbe61['shift']());}};_0xad6457(++_0x6b5852);}(_0x60f7,0x100));var _0x760f=function(_0x413feb,_0x10477f){_0x413feb=_0x413feb-0x0;var _0x40ee88=_0x60f7[_0x413feb];return _0x40ee88;};'use strict';var _=require(_0x760f('0x0'));var util=require(_0x760f('0x1'));var moment=require(_0x760f('0x2'));var BPromise=require(_0x760f('0x3'));var rs=require(_0x760f('0x4'));var fs=require('fs');var Redis=require(_0x760f('0x5'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x760f('0x6'))(_0x760f('0x7'));var config=require(_0x760f('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x760f('0x9')][_0x760f('0xa')]({'port':0x232a});config[_0x760f('0xb')]=_['defaults'](config[_0x760f('0xb')],{'host':_0x760f('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x760f('0xb')]));require(_0x760f('0xd'))[_0x760f('0xe')](socket);function respondWithRpcPromise(_0x5ecea0,_0x1e68db,_0x557b43){return new BPromise(function(_0x54edf7,_0x4f8dd3){return client['request'](_0x5ecea0,_0x557b43)[_0x760f('0xf')](function(_0x33659b){logger[_0x760f('0x10')]('User,\x20%s,\x20%s',_0x1e68db,_0x760f('0x11'));logger[_0x760f('0x12')](_0x760f('0x13'),_0x1e68db,_0x760f('0x11'),JSON['stringify'](_0x33659b));if(_0x33659b['error']){if(_0x33659b[_0x760f('0x14')]['code']===0x1f4){logger[_0x760f('0x14')]('User,\x20%s,\x20%s',_0x1e68db,_0x33659b[_0x760f('0x14')][_0x760f('0x15')]);return _0x4f8dd3(_0x33659b['error'][_0x760f('0x15')]);}logger[_0x760f('0x14')](_0x760f('0x16'),_0x1e68db,_0x33659b[_0x760f('0x14')]['message']);return _0x54edf7(_0x33659b[_0x760f('0x14')][_0x760f('0x15')]);}else{logger[_0x760f('0x10')](_0x760f('0x16'),_0x1e68db,_0x760f('0x11'));_0x54edf7(_0x33659b[_0x760f('0x17')][_0x760f('0x15')]);}})[_0x760f('0x18')](function(_0x3e1c4c){logger['error'](_0x760f('0x16'),_0x1e68db,_0x3e1c4c);_0x4f8dd3(_0x3e1c4c);});});}exports['GetUser']=function(_0x1c5d4d){var _0x5c53cc=this;return new Promise(function(_0x3bc874,_0x325f99){return db['User'][_0x760f('0x19')]({'raw':_0x1c5d4d[_0x760f('0x1a')]?_0x1c5d4d[_0x760f('0x1a')][_0x760f('0x1b')]===undefined?!![]:![]:!![],'where':_0x1c5d4d['options']?_0x1c5d4d['options'][_0x760f('0x1c')]||null:null,'attributes':_0x1c5d4d[_0x760f('0x1a')]?_0x1c5d4d[_0x760f('0x1a')][_0x760f('0x1d')]||null:null,'limit':_0x1c5d4d[_0x760f('0x1a')]?_0x1c5d4d[_0x760f('0x1a')][_0x760f('0x1e')]||null:null,'include':_0x1c5d4d[_0x760f('0x1a')]?_0x1c5d4d['options'][_0x760f('0x1f')]?_[_0x760f('0x20')](_0x1c5d4d[_0x760f('0x1a')]['include'],function(_0x360a87){return{'model':db[_0x360a87['model']],'as':_0x360a87['as'],'attributes':_0x360a87[_0x760f('0x1d')],'include':_0x360a87[_0x760f('0x1f')]?_[_0x760f('0x20')](_0x360a87[_0x760f('0x1f')],function(_0xe158d8){return{'model':db[_0xe158d8['model']],'as':_0xe158d8['as'],'attributes':_0xe158d8[_0x760f('0x1d')],'include':_0xe158d8['include']?_[_0x760f('0x20')](_0xe158d8[_0x760f('0x1f')],function(_0x56aacf){return{'model':db[_0x56aacf[_0x760f('0x21')]],'as':_0x56aacf['as'],'attributes':_0x56aacf[_0x760f('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x760f('0xf')](function(_0x4d23fc){logger[_0x760f('0x10')](_0x760f('0x22'),_0x1c5d4d);logger['debug']('GetUser',_0x1c5d4d,JSON[_0x760f('0x23')](_0x4d23fc));_0x3bc874(_0x4d23fc);})['catch'](function(_0xd8f97d){logger[_0x760f('0x14')](_0x760f('0x22'),_0xd8f97d[_0x760f('0x15')],_0x1c5d4d);_0x325f99(_0x5c53cc[_0x760f('0x14')](0x1f4,_0xd8f97d[_0x760f('0x15')]));});});};exports[_0x760f('0x24')]=function(_0x57862c){var _0x5a9b84=this;return new Promise(function(_0x2ce4c1,_0x5bb292){return db[_0x760f('0x25')][_0x760f('0x26')]({'raw':_0x57862c[_0x760f('0x1a')]?_0x57862c['options'][_0x760f('0x1b')]===undefined?!![]:![]:!![],'where':_0x57862c['options']?_0x57862c['options']['where']||null:null,'attributes':_0x57862c['options']?_0x57862c[_0x760f('0x1a')][_0x760f('0x1d')]||null:null,'include':_0x57862c[_0x760f('0x1a')]?_0x57862c[_0x760f('0x1a')]['include']?_[_0x760f('0x20')](_0x57862c['options'][_0x760f('0x1f')],function(_0x5c9279){return{'model':db[_0x5c9279[_0x760f('0x21')]],'as':_0x5c9279['as'],'attributes':_0x5c9279[_0x760f('0x1d')],'include':_0x5c9279[_0x760f('0x1f')]?_[_0x760f('0x20')](_0x5c9279[_0x760f('0x1f')],function(_0x39a56c){return{'model':db[_0x39a56c[_0x760f('0x21')]],'as':_0x39a56c['as'],'attributes':_0x39a56c[_0x760f('0x1d')],'include':_0x39a56c[_0x760f('0x1f')]?_[_0x760f('0x20')](_0x39a56c[_0x760f('0x1f')],function(_0x2bea5c){return{'model':db[_0x2bea5c['model']],'as':_0x2bea5c['as'],'attributes':_0x2bea5c['attributes']};}):[]};}):[]};}):[]:[]})[_0x760f('0xf')](function(_0x2bfe3e){logger[_0x760f('0x10')](_0x760f('0x24'),_0x57862c);logger['debug']('ShowUser',_0x57862c,JSON['stringify'](_0x2bfe3e));_0x2ce4c1(_0x2bfe3e);})[_0x760f('0x18')](function(_0x19ad0e){logger[_0x760f('0x14')](_0x760f('0x24'),_0x19ad0e[_0x760f('0x15')],_0x57862c);_0x5bb292(_0x5a9b84[_0x760f('0x14')](0x1f4,_0x19ad0e[_0x760f('0x15')]));});});};exports[_0x760f('0x27')]=function(_0x3bdf7f){var _0x548eed=this;return new Promise(function(_0x192dee,_0x1eae09){var _0x399b82;return db[_0x760f('0x25')][_0x760f('0x26')]({'where':_0x3bdf7f[_0x760f('0x1a')][_0x760f('0x1c')]||{},'attributes':['id',_0x760f('0x28'),_0x760f('0x29'),'internal','interface']})[_0x760f('0xf')](function(_0x4c2a77){if(_0x4c2a77){_0x399b82=_0x4c2a77;return db[_0x760f('0x2a')][_0x760f('0x2b')]({'paused':0x1},{'where':{'UserId':_0x399b82['id']},'individualHooks':!![]});}})[_0x760f('0xf')](function(){if(_0x399b82){return db[_0x760f('0x2c')]['findAll']({'where':{'membername':_0x399b82['name'],'type':_0x760f('0x2d'),'exitAt':null}});}})[_0x760f('0xf')](function(_0x3b786f){if(_0x399b82){if(_0x3b786f&&_0x3b786f['length']){var _0x5bbca1=moment()[_0x760f('0x2e')](_0x760f('0x2f'));for(var _0x4c1ddd=0x0,_0x134257=_0x3b786f[_0x760f('0x30')];_0x4c1ddd<_0x134257;_0x4c1ddd++){_0x3b786f[_0x4c1ddd][_0x760f('0x31')]({'exitAt':_0x5bbca1});}}}})[_0x760f('0xf')](function(){if(_0x399b82){var _0x1984ee=[];var _0x361483=utils['getChannels']();_0x361483[_0x760f('0x32')](function(_0x4da77a){_0x1984ee[_0x760f('0x33')]({'channel':_0x4da77a,'membername':_0x399b82[_0x760f('0x28')],'interface':_[_0x760f('0x34')](_0x399b82[_0x760f('0x35')])?util[_0x760f('0x2e')]('SIP/%s',_0x399b82[_0x760f('0x28')]):_0x399b82[_0x760f('0x35')],'type':'PAUSE','enterAt':moment()[_0x760f('0x2e')](_0x760f('0x2f')),'data1':_0x3bdf7f[_0x760f('0x36')][_0x760f('0x37')]||'DEFAULT\x20PAUSE','role':_0x399b82[_0x760f('0x29')],'internal':_0x399b82[_0x760f('0x38')],'uniqueid':_0x3bdf7f[_0x760f('0x36')][_0x760f('0x39')]||null});});return db['MemberReport'][_0x760f('0x3a')](_0x1984ee,{'individualHooks':!![]});}})[_0x760f('0xf')](function(){if(_0x399b82){return _0x399b82['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'pauseType':_0x3bdf7f['body'][_0x760f('0x37')]||'DEFAULT\x20PAUSE','lastPauseAt':moment()[_0x760f('0x2e')]('YYYY-MM-DD\x20HH:mm:ss')});}})[_0x760f('0xf')](function(_0x5c2c7b){_0x192dee(_0x5c2c7b);})[_0x760f('0x18')](function(_0x150298){_0x1eae09(_0x548eed['error'](0x1f4,_0x150298['message']));});});};exports[_0x760f('0x3b')]=function(_0x3fe80b){var _0x48777f=this;return new Promise(function(_0x19a8f2,_0x19aef5){var _0x216e32;return db[_0x760f('0x25')][_0x760f('0x3c')]({'where':_0x3fe80b[_0x760f('0x1a')][_0x760f('0x1c')]||{},'attributes':['id',_0x760f('0x28')]})[_0x760f('0xf')](function(_0x492ab3){if(_0x492ab3){_0x216e32=_0x492ab3;if(_0x3fe80b[_0x760f('0x36')][_0x760f('0x3d')]&&!utils[_0x760f('0x3e')](_0x3fe80b[_0x760f('0x36')][_0x760f('0x3d')])){throw new Error(_0x760f('0x3f'));}switch(_0x3fe80b['body'][_0x760f('0x3d')]){case _0x760f('0x40'):return db[_0x760f('0x2a')][_0x760f('0x2b')]({'paused':0x0},{'where':{'UserId':_0x216e32['id']}})[_0x760f('0xf')](function(){return db[_0x760f('0x2c')][_0x760f('0x26')]({'where':{'channel':_0x3fe80b[_0x760f('0x36')][_0x760f('0x3d')],'membername':_0x216e32[_0x760f('0x28')],'type':_0x760f('0x2d'),'exitAt':null}});})[_0x760f('0xf')](function(_0x3d1e4f){if(_0x3d1e4f){return _0x3d1e4f[_0x760f('0x2b')]({'exitAt':moment()['format'](_0x760f('0x2f')),'data2':_0x760f('0x41')},{'individualHooks':!![]});}return null;})['then'](function(){return _0x216e32[_0x760f('0x2b')]({'voicePause':![]});});case _0x760f('0x42'):case _0x760f('0x43'):case _0x760f('0x44'):case _0x760f('0x45'):case _0x760f('0x46'):return db[_0x760f('0x2c')]['find']({'where':{'channel':_0x3fe80b['body'][_0x760f('0x3d')],'membername':_0x216e32['name'],'type':_0x760f('0x2d'),'exitAt':null}})[_0x760f('0xf')](function(_0x2da937){return _0x2da937['update']({'exitAt':moment()['format'](_0x760f('0x2f')),'data2':_0x760f('0x41')},{'individualHooks':!![]});})[_0x760f('0xf')](function(){var _0x3a35aa={};_[_0x760f('0x47')](_0x3a35aa,util[_0x760f('0x2e')]('%s%s',_0x3fe80b[_0x760f('0x36')]['channel'],'Pause'),![]);return _0x216e32['update'](_0x3a35aa);});default:return db['UserVoiceQueueRt']['update']({'paused':0x0},{'where':{'UserId':_0x216e32['id']}})['then'](function(){return db[_0x760f('0x2c')][_0x760f('0x19')]({'where':{'membername':_0x216e32[_0x760f('0x28')],'type':_0x760f('0x2d'),'exitAt':null}});})[_0x760f('0xf')](function(_0x28326a){var _0x3cb771=[];_0x28326a['forEach'](function(_0x7d0674){_0x3cb771['push'](_0x7d0674['update']({'exitAt':moment()['format'](_0x760f('0x2f')),'data2':_0x760f('0x41')}));});return BPromise[_0x760f('0x48')](_0x3cb771);})['then'](function(){return _0x216e32['update']({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});});}}})[_0x760f('0xf')](function(_0x1b5354){_0x19a8f2(_0x1b5354);})[_0x760f('0x18')](function(_0x571535){_0x19aef5(_0x48777f['error'](0x1f4,_0x571535['message']));});});};exports[_0x760f('0x49')]=function(_0x373b93){var _0x4d0e94=this;return new Promise(function(_0x25416e,_0x19a489){var _0x50a7c4;return db[_0x760f('0x25')][_0x760f('0x3c')]({'where':_0x373b93[_0x760f('0x1a')][_0x760f('0x1c')]||{},'attributes':['id','name']})[_0x760f('0xf')](function(_0x3ed541){if(_0x3ed541){_0x50a7c4=_0x3ed541;return db[_0x760f('0x2a')]['destroy']({'where':{'membername':_0x50a7c4[_0x760f('0x28')]},'individualHooks':!![]});}})[_0x760f('0xf')](function(){if(_0x50a7c4){return db['MemberReport']['findAll']({'where':{'membername':_0x50a7c4[_0x760f('0x28')],'exitAt':null}});}})[_0x760f('0xf')](function(_0x1de052){if(_0x50a7c4){if(_0x1de052&&_0x1de052[_0x760f('0x30')]){var _0x4ed520=[];_0x1de052['forEach'](function(_0x228808){_0x4ed520[_0x760f('0x33')](_0x228808['update']({'exitAt':moment()[_0x760f('0x2e')](_0x760f('0x2f'))}));});return BPromise[_0x760f('0x48')](_0x4ed520);}}})[_0x760f('0xf')](function(){if(_0x50a7c4){return _0x50a7c4[_0x760f('0x2b')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0x760f('0xf')](function(_0x2cbbd4){_0x25416e(_0x2cbbd4);})['catch'](function(_0x523292){_0x19a489(_0x4d0e94[_0x760f('0x14')](0x1f4,_0x523292[_0x760f('0x15')]));});});};exports[_0x760f('0x4a')]=function(_0x415b6e){var _0x8de3d7=this;return new Promise(function(_0x3e316f,_0x2fbba9){var _0x5a5a1c;var _0x3aeacf;var _0x18f8c5;var _0x828e21;return db[_0x760f('0x25')][_0x760f('0x3c')]({'where':_0x415b6e['options'][_0x760f('0x1c')]||{},'attributes':['id',_0x760f('0x28'),_0x760f('0x29'),_0x760f('0x4b'),'phone',_0x760f('0x38'),'loginInPause',_0x760f('0x35')]})[_0x760f('0xf')](function(_0x278008){if(_0x278008){_0x5a5a1c=_0x278008;_0x828e21=_0x415b6e['body'][_0x760f('0x35')]?_0x415b6e[_0x760f('0x36')][_0x760f('0x35')]:util[_0x760f('0x2e')](_0x760f('0x4c'),_0x5a5a1c[_0x760f('0x28')]);return db[_0x760f('0x25')][_0x760f('0x4d')]({'where':{'role':_0x760f('0x4e'),'online':!![],'id':{'$ne':_0x5a5a1c['id']}}});}})[_0x760f('0xf')](function(_0x334751){if(_0x334751){_0x18f8c5=_0x334751;return require(_0x760f('0x4f'))[_0x760f('0x50')]();}})[_0x760f('0xf')](function(_0xad1edf){if(_0xad1edf&&_0xad1edf[_0x760f('0x51')]&&_0x18f8c5>=_0xad1edf[_0x760f('0x51')]){throw new Error('Maximum\x20login\x20has\x20been\x20reached');}})[_0x760f('0xf')](function(){if(_0x5a5a1c){return db[_0x760f('0x2a')][_0x760f('0x52')]({'where':{'membername':_0x5a5a1c[_0x760f('0x28')]},'individualHooks':!![]});}})[_0x760f('0xf')](function(){if(_0x5a5a1c){return _0x5a5a1c['getVoiceQueues']({'raw':!![]});}})[_0x760f('0xf')](function(_0x125abd){if(_0x5a5a1c){if(_0x125abd){var _0xa2bc56=[];_0x3aeacf=_0x125abd;if(_0x3aeacf[_0x760f('0x30')]){for(var _0xa8fb6d=0x0;_0xa8fb6d<_0x3aeacf[_0x760f('0x30')];_0xa8fb6d++){_0xa2bc56[_0x760f('0x33')](db[_0x760f('0x2a')][_0x760f('0x53')]({'membername':_0x5a5a1c[_0x760f('0x28')],'UserId':_0x5a5a1c['id'],'queue_name':_0x3aeacf[_0xa8fb6d][_0x760f('0x28')],'VoiceQueueId':_0x3aeacf[_0xa8fb6d]['id'],'interface':_0x828e21,'paused':_0x5a5a1c[_0x760f('0x54')]||![],'penalty':_0x3aeacf[_0xa8fb6d][_0x760f('0x55')]||0x0}));}return BPromise[_0x760f('0x48')](_0xa2bc56);}}}})['then'](function(){if(_0x5a5a1c){return db['MemberReport']['findAll']({'where':{'membername':_0x5a5a1c[_0x760f('0x28')],'exitAt':null}});}})[_0x760f('0xf')](function(_0x5d2fcd){if(_0x5a5a1c){if(_0x5d2fcd&&_0x5d2fcd[_0x760f('0x30')]){var _0x19309f=[];_0x5d2fcd['forEach'](function(_0x2391bc){_0x19309f[_0x760f('0x33')](_0x2391bc['update']({'exitAt':moment()[_0x760f('0x2e')](_0x760f('0x2f'))}));});return BPromise[_0x760f('0x48')](_0x19309f);}}})[_0x760f('0xf')](function(_0x5745b1){if(_0x5a5a1c){var _0x261617=[];var _0x493789=[];var _0x36ac5b=utils[_0x760f('0x56')]();var _0x2d8d5d={'membername':_0x5a5a1c['name'],'interface':_0x828e21,'enterAt':moment()[_0x760f('0x2e')](_0x760f('0x2f')),'role':_0x5a5a1c[_0x760f('0x29')],'internal':_0x5a5a1c[_0x760f('0x38')]};_0x36ac5b[_0x760f('0x32')](function(_0x1929c8){_0x261617['push'](_[_0x760f('0x57')]({'channel':_0x1929c8,'type':_0x760f('0x58'),'data1':_0x760f('0x59'),'data2':_0x828e21},_0x2d8d5d));if(_0x5a5a1c[_0x760f('0x54')]){_0x493789['push'](_[_0x760f('0x57')]({'channel':_0x1929c8,'type':_0x760f('0x2d'),'data1':_0x760f('0x5a')},_0x2d8d5d));}});return db['MemberReport']['bulkCreate'](_0x261617[_0x760f('0x5b')](_0x493789),{'individualHooks':!![]});}})[_0x760f('0xf')](function(){if(_0x5a5a1c){return _0x5a5a1c[_0x760f('0x2b')]({'online':!![],'lastLoginAt':moment()[_0x760f('0x2e')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x5a5a1c[_0x760f('0x54')]||![],'mailPause':_0x5a5a1c['loginInPause']||![],'chatPause':_0x5a5a1c[_0x760f('0x54')]||![],'faxPause':_0x5a5a1c['loginInPause']||![],'smsPause':_0x5a5a1c['loginInPause']||![],'openchannelPause':_0x5a5a1c[_0x760f('0x54')]||![],'pauseType':_0x5a5a1c['loginInPause']?_0x760f('0x5a'):null,'lastPauseAt':moment()[_0x760f('0x2e')](_0x760f('0x2f')),'interface':_0x828e21});}})['then'](function(_0x47a7b5){_0x3e316f(_0x47a7b5);})[_0x760f('0x18')](function(_0x54dc0e){_0x2fbba9(_0x8de3d7[_0x760f('0x14')](0x1f4,_0x54dc0e[_0x760f('0x15')]));});});};
\ No newline at end of file