53ea2192f116140d344da6f26848a868c3745719
[motion-next.git] / server / api / user / user.model.js
1 const a650_0x232e=['ChanSpy','provider','./user.attributes','encryptPassword','bulkCreate','VoiceExtension','length','_XCALLY_MIXMONITOR_FORMAT=%s','exports','Hangup','base64','defaults','chanspy','SIP/%s,,tTxXU(xcally-mixmonitor-context)','then','utf8_bin','indexOf','makeSaltAsync','sha1',':asterisk:','CDR(type)=internal','StopMixMonitor','name','push','CDR(type)=%s','from','toString','format','from-sip','local','prototype','crypto','MixMonitor','isEmpty','concat','password','sequelize','User','SIP/%s,%s','prefix','context','join','salt','users','updateMd5Password','destroy','system','WAV','lodash','options','changed','findAll','catch','models','Missing\x20Callback','internal','Dial','pbkdf2Sync','SIP/%s,,tTxX','function','record','VoiceChanSpy','extensionMonitor','updatePassword','Invalid\x20password','Set','md5','makeSalt','authenticate','resolve','gsm','utf8','auth','randomBytes','merge','md5secret'];(function(_0x3f97e3,_0x232e4d){const _0x4e3424=function(_0x3db10d){while(--_0x3db10d){_0x3f97e3['push'](_0x3f97e3['shift']());}};_0x4e3424(++_0x232e4d);}(a650_0x232e,0x68));const a650_0x4e34=function(_0x3f97e3,_0x232e4d){_0x3f97e3=_0x3f97e3-0x0;let _0x4e3424=a650_0x232e[_0x3f97e3];return _0x4e3424;};const _0x1b4fe8=a650_0x4e34;'use strict';const _=require(_0x1b4fe8('0x14')),util=require('util'),crypto=require(_0x1b4fe8('0x3')),md5=require(_0x1b4fe8('0x26')),sequelize=require(_0x1b4fe8('0x8')),{Op}=sequelize,attributes=require(_0x1b4fe8('0x32')),addUserApplication=function(_0x3db10d,_0x5956b6){const _0x47e84a=_0x1b4fe8,_0x217977=['wav',_0x47e84a('0x13'),_0x47e84a('0x2a')],_0x2be741={'context':_0x3db10d[_0x47e84a('0xc')]||_0x47e84a('0x0'),'exten':_0x5956b6,'type':'system','isApp':![],'UserId':_0x3db10d['id']},_0xb59156=[{'app':_0x47e84a('0x25'),'appdata':_0x47e84a('0x44')}];_0x3db10d[_0x47e84a('0x22')]&&_['includes'](_0x217977,_0x3db10d['extensionMonitor'])?(_0xb59156[_0x47e84a('0x47')]({'app':_0x47e84a('0x25'),'appdata':'_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}'}),_0xb59156[_0x47e84a('0x47')]({'app':'Set','appdata':util[_0x47e84a('0x4b')](_0x47e84a('0x37'),_0x3db10d[_0x47e84a('0x22')])}),_0xb59156[_0x47e84a('0x47')]({'app':_0x47e84a('0x1c'),'appdata':util[_0x47e84a('0x4b')](_0x47e84a('0x3d'),_0x3db10d[_0x47e84a('0x46')])})):_0xb59156[_0x47e84a('0x47')]({'app':_0x47e84a('0x1c'),'appdata':util[_0x47e84a('0x4b')](_0x47e84a('0x1e'),_0x3db10d[_0x47e84a('0x46')])});_0xb59156[_0x47e84a('0x47')]({'app':_0x47e84a('0x39')});for(let _0x4a7b26=0x0;_0x4a7b26<_0xb59156[_0x47e84a('0x36')];_0x4a7b26++){_0xb59156[_0x4a7b26]['priority']=_0x4a7b26+0x1,_0xb59156[_0x4a7b26]=_[_0x47e84a('0x3b')](_0xb59156[_0x4a7b26],_0x2be741);}return _0xb59156;},addChanSpyApplications=function(_0x309810,_0x173d70,_0x1a933f){const _0x1461eb=_0x1b4fe8,_0x1ce4bd={'context':_0x309810[_0x1461eb('0xc')]||'from-sip','type':_0x1461eb('0x12'),'isApp':![],'UserId':_0x309810['id']},_0x5660e2=[];for(let _0x110627=0x0,_0x1af8dc=0x1;_0x110627<_0x1a933f[_0x1461eb('0x36')];_0x110627++,_0x1af8dc=0x1){const _0x1206be={'exten':util[_0x1461eb('0x4b')]('%s%s',_0x1a933f[_0x110627][_0x1461eb('0xb')],_0x173d70),'ChanSpyId':_0x1a933f[_0x110627]['id']};_0x5660e2[_0x1461eb('0x47')](_[_0x1461eb('0x2e')]({'app':_0x1461eb('0x25'),'appdata':util[_0x1461eb('0x4b')](_0x1461eb('0x48'),_0x1461eb('0x3c')),'priority':_0x1af8dc++},_0x1ce4bd,_0x1206be)),_0x1a933f[_0x110627][_0x1461eb('0x20')]&&_0x5660e2[_0x1461eb('0x47')](_[_0x1461eb('0x2e')]({'app':_0x1461eb('0x4'),'appdata':util[_0x1461eb('0x4b')]('${UNIQUEID}.%s,ab',_0x1a933f[_0x110627]['recordingFormat']),'priority':_0x1af8dc++},_0x1ce4bd,_0x1206be)),_0x1a933f[_0x110627][_0x1461eb('0x2c')]&&_0x5660e2[_0x1461eb('0x47')](_['merge']({'app':'Authenticate','appdata':_0x1a933f[_0x110627]['password'],'priority':_0x1af8dc++},_0x1ce4bd,_0x1206be)),_0x5660e2[_0x1461eb('0x47')](_[_0x1461eb('0x2e')]({'app':_0x1461eb('0x30'),'appdata':util[_0x1461eb('0x4b')](_0x1461eb('0xa'),_0x309810[_0x1461eb('0x46')],_0x1a933f[_0x110627][_0x1461eb('0x15')]?_0x1a933f[_0x110627][_0x1461eb('0x15')][_0x1461eb('0xd')](''):''),'priority':_0x1af8dc++},_0x1ce4bd,_0x1206be)),_0x1a933f[_0x110627][_0x1461eb('0x20')]&&_0x5660e2['push'](_[_0x1461eb('0x2e')]({'app':_0x1461eb('0x45'),'priority':_0x1af8dc++},_0x1ce4bd,_0x1206be));}return _0x5660e2;},getChanSpy=function(_0x194df5,_0x3143c7){return new Promise(function(_0x459c70,_0x59c2c9){const _0x1e1655=a650_0x4e34;return _0x194df5[_0x1e1655('0x21')][_0x1e1655('0x17')]()[_0x1e1655('0x3e')](function(_0x3c541c){const _0x5d09d0=_0x1e1655;if(_0x3c541c){let _0x2627b1=addChanSpyApplications(_0x3143c7,_0x3143c7[_0x5d09d0('0x1b')],_0x3c541c);return _0x3143c7['internal']!=_0x3143c7['name']&&(_0x2627b1=_0x2627b1[_0x5d09d0('0x6')](addChanSpyApplications(_0x3143c7,_0x3143c7[_0x5d09d0('0x46')],_0x3c541c))),_0x459c70(_0x2627b1);}return _0x459c70([]);})[_0x1e1655('0x18')](function(_0x288169){_0x59c2c9(_0x288169);});});},authTypes=['google',_0x1b4fe8('0x1')];module[_0x1b4fe8('0x38')]=function(_0x31510d){const _0x16a42a=_0x1b4fe8,_0x1df624=_0x31510d[_0x16a42a('0x19')],_0x251da6=_0x31510d['define'](_0x16a42a('0x9'),attributes,{'tableName':_0x16a42a('0xf'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x30c0f4){const _0x3ac1ed=_0x16a42a;return _0x30c0f4[_0x3ac1ed('0x10')](),_0x30c0f4[_0x3ac1ed('0x23')]();},'beforeUpdate':function(_0x274882){const _0x1c1e9f=_0x16a42a;return _0x274882[_0x1c1e9f('0x16')]('password')?(_0x274882[_0x1c1e9f('0x10')](),_0x274882['updatePassword']()):Promise[_0x1c1e9f('0x29')]();},'afterCreate':function(_0xb900e4){const _0x3c9ae6=_0x16a42a;let _0x31eca6=addUserApplication(_0xb900e4,_0xb900e4[_0x3c9ae6('0x1b')]);return _0xb900e4[_0x3c9ae6('0x1b')]!=_0xb900e4[_0x3c9ae6('0x46')]&&(_0x31eca6=_0x31eca6[_0x3c9ae6('0x6')](addUserApplication(_0xb900e4,_0xb900e4['name']))),_0x1df624[_0x3c9ae6('0x35')][_0x3c9ae6('0x34')](_0x31eca6)[_0x3c9ae6('0x3e')](function(){if(_0xb900e4['chanspy'])return getChanSpy(_0x1df624,_0xb900e4);})[_0x3c9ae6('0x3e')](function(_0x5157e8){const _0x22624b=_0x3c9ae6;return _0x5157e8&&_0x5157e8[_0x22624b('0x36')]?_0x1df624[_0x22624b('0x35')]['bulkCreate'](_0x5157e8):null;})['catch'](function(_0x2a4541){return _0x2a4541;});},'afterUpdate':function(_0x27c913){const _0x2ff711=_0x16a42a;return Promise['resolve']()[_0x2ff711('0x3e')](function(){const _0x801dc5=_0x2ff711;if(_0x27c913['changed'](_0x801dc5('0x3c'))||_0x27c913[_0x801dc5('0x16')](_0x801dc5('0xc')))return _0x1df624['VoiceExtension'][_0x801dc5('0x11')]({'where':{'UserId':_0x27c913['id'],'type':_0x801dc5('0x12'),'ChanSpyId':{[Op['ne']]:null}}})['then'](function(){const _0x32c02a=_0x801dc5;if(_0x27c913[_0x32c02a('0x3c')])return getChanSpy(_0x1df624,_0x27c913)[_0x32c02a('0x3e')](function(_0x3be64b){const _0x594b21=_0x32c02a;if(_0x3be64b&&_0x3be64b[_0x594b21('0x36')])return _0x1df624['VoiceExtension'][_0x594b21('0x34')](_0x3be64b);});});})[_0x2ff711('0x3e')](function(){const _0x3bcc4a=_0x2ff711;return _0x27c913[_0x3bcc4a('0x16')]('extensionMonitor')||_0x27c913[_0x3bcc4a('0x16')](_0x3bcc4a('0xc'))?_0x1df624[_0x3bcc4a('0x35')][_0x3bcc4a('0x11')]({'where':{'UserId':_0x27c913['id'],'type':_0x3bcc4a('0x12'),'ChanSpyId':null}})['then'](function(){const _0x149d84=_0x3bcc4a;let _0x330578=addUserApplication(_0x27c913,_0x27c913[_0x149d84('0x1b')]);return _0x27c913[_0x149d84('0x1b')]!=_0x27c913[_0x149d84('0x46')]&&(_0x330578=_0x330578['concat'](addUserApplication(_0x27c913,_0x27c913[_0x149d84('0x46')]))),_0x1df624['VoiceExtension']['bulkCreate'](_0x330578);}):null;})[_0x2ff711('0x18')](function(_0x31242e){return _0x31242e;});},'afterDestroy':function(_0x242a9e){const _0x2b73ab=_0x16a42a;return _0x1df624[_0x2b73ab('0x35')][_0x2b73ab('0x11')]({'where':{'UserId':_0x242a9e['id'],'type':_0x2b73ab('0x12')}});}},'charset':_0x16a42a('0x2b'),'collate':_0x16a42a('0x3f')});return _0x251da6['prototype'][_0x16a42a('0x28')]=function(_0x4df440,_0xa28220){const _0x4e0ddb=_0x16a42a;if(!_0xa28220)return this[_0x4e0ddb('0x7')]===this['encryptPassword'](_0x4df440);const _0x281a99=this;this[_0x4e0ddb('0x33')](_0x4df440,function(_0x56bd6b,_0x41bbbd){_0x56bd6b&&_0xa28220(_0x56bd6b),_0x281a99['password']===_0x41bbbd?_0xa28220(null,!![]):_0xa28220(null,![]);});},_0x251da6[_0x16a42a('0x2')][_0x16a42a('0x27')]=function(_0x1884f9,_0x351bcd){const _0x474e4a=_0x16a42a,_0x5c65ad=0x10;if(typeof arguments[0x0]===_0x474e4a('0x1f'))_0x351bcd=arguments[0x0],_0x1884f9=_0x5c65ad;else{if(typeof arguments[0x1]===_0x474e4a('0x1f'))_0x351bcd=arguments[0x1];else throw new Error(_0x474e4a('0x1a'));}return!_0x1884f9&&(_0x1884f9=_0x5c65ad),crypto[_0x474e4a('0x2d')](_0x1884f9,function(_0x20173b,_0x551f7a){const _0x213a15=_0x474e4a;return _0x20173b&&_0x351bcd(_0x20173b),_0x351bcd(null,_0x551f7a['toString'](_0x213a15('0x3a')));});},_0x251da6[_0x16a42a('0x2')]['makeSaltAsync']=async function(_0x118edc=0x10){return new Promise((_0x227aea,_0xc2c7a5)=>{const _0x3842cb=a650_0x4e34;crypto[_0x3842cb('0x2d')](_0x118edc,function(_0x130e1c,_0x59e086){const _0x15f99e=_0x3842cb;return _0x130e1c&&_0xc2c7a5(_0x130e1c),_0x227aea(_0x59e086['toString'](_0x15f99e('0x3a')));});});},_0x251da6['prototype'][_0x16a42a('0x33')]=function(_0x5dacc8,_0x4f0785){const _0x3f4519=_0x16a42a;if(!_0x5dacc8||!this[_0x3f4519('0xe')])return _0x4f0785?_0x4f0785(null):null;const _0x302f0c=0x2710,_0x5c0f35=0x40,_0x14b6d6=Buffer[_0x3f4519('0x49')](this[_0x3f4519('0xe')],_0x3f4519('0x3a'));if(!_0x4f0785)return crypto[_0x3f4519('0x1d')](_0x5dacc8,_0x14b6d6,_0x302f0c,_0x5c0f35,_0x3f4519('0x42'))[_0x3f4519('0x4a')]('base64');return crypto['pbkdf2'](_0x5dacc8,_0x14b6d6,_0x302f0c,_0x5c0f35,_0x3f4519('0x42'),function(_0x1fd0b5,_0x45a26f){const _0x23f925=_0x3f4519;return _0x1fd0b5&&_0x4f0785(_0x1fd0b5),_0x4f0785(null,_0x45a26f[_0x23f925('0x4a')]('base64'));});},_0x251da6[_0x16a42a('0x2')][_0x16a42a('0x23')]=async function(){const _0x56e283=_0x16a42a;if(!this['password'])return null;if(!_[_0x56e283('0x5')](this['password'])&&authTypes[_0x56e283('0x40')](this[_0x56e283('0x31')])===-0x1)throw new Error(_0x56e283('0x24'));return this[_0x56e283('0xe')]=await this[_0x56e283('0x41')](),new Promise((_0x1b76b5,_0x415813)=>{this['encryptPassword'](this['password'],(_0x500b65,_0x48be86)=>{const _0x37fde9=a650_0x4e34;_0x500b65?_0x415813(_0x500b65):(this[_0x37fde9('0x7')]=_0x48be86,_0x1b76b5());});});},_0x251da6['prototype'][_0x16a42a('0x10')]=function(){const _0x5296f9=_0x16a42a;this[_0x5296f9('0x2f')]=md5(this[_0x5296f9('0x46')]+_0x5296f9('0x43')+this['password']);},_0x251da6;};