Built motion from commit eddce310.|2.6.12
[motion2.git] / server / components / auth / service.js
index c623145..65ac43d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf970=['../encryptor','lodash','jsonwebtoken','express-jwt','composable-middleware','crypto','bluebird','util','moment','secrets','session','role','fullname','name','userpic','md5secret','voicePause','chatPause','faxPause','openchannelPause','pauseType','showWebBar','lastLoginAt','lastPauseAt','allowmessenger','passwordResetAt','alias','phoneBarAutoAnswer','phoneBarAutoAnswerDelay','phoneBarDnd','phoneBarEnableRecording','phoneBarExpires','phoneBarPrefixRequired','phoneBarRemoteControl','phoneBarRemoteControlPort','userProfileId','privacyEnabled','settingsEnabled','isChatInteractionAuthorized','isAuthenticated','use','user','ChatInteraction','findOne','params','closed','then','status','disposition','unmanaged','json','Unmanaged.','Forbidden.','headers','authorization','Basic','User','find','authenticate','pass','Wrong\x20credentials.','catch','startsWith','Unknown\x20authorization\x20format','query','apikey','getUuid','sub','Setting','allowedLoginAttempts','isEqual','apiKeyNonce','nonce','blocked','blockDuration','blockedAt','add','minutes','Invalid\x20API\x20access\x20key','User\x20not\x20found.','User\x20object\x20not\x20found.','canUpdate','getLicense','Forbidden','isMiddleware','signToken','setTokenCookie','cookie','motion.token','send','retrieveApiKey','isNil','apiKeyIat','generateApiKey','Please\x20use\x20the\x20previous\x20API\x20access\x20key\x20to\x20generate\x20a\x20new\x20one','test','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','validatePasswordHistory','decryptString','split','toLowerCase','format','The\x20password\x20must\x20be\x20different\x20from\x20the\x20previous\x20%d\x20passwords.\x20Please\x20choose\x20another\x20one.','updatePasswordsHistory','length','promisify','payload','options','verify','randomBytes','hex','floor','now','toString','HS512','../../mysqldb','../../config/license/hardware','../../config/license/util'];(function(_0x45d1fd,_0x463212){var _0xd0e542=function(_0x23ebc9){while(--_0x23ebc9){_0x45d1fd['push'](_0x45d1fd['shift']());}};_0xd0e542(++_0x463212);}(_0xf970,0x1d9));var _0x0f97=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf970[_0x3dd15e];return _0x231fd0;};'use strict';var db=require(_0x0f97('0x0'))['db'];var config=require('../../config/environment');var hardwareConf=require(_0x0f97('0x1'));var licenseUtil=require(_0x0f97('0x2'));var encryptor=require(_0x0f97('0x3'));var _=require(_0x0f97('0x4'));var jwt=require(_0x0f97('0x5'));var expressJwt=require(_0x0f97('0x6'));var compose=require(_0x0f97('0x7'));var basicAuth=require('basic-auth');var crypto=require(_0x0f97('0x8'));var BPromise=require(_0x0f97('0x9'));var util=require(_0x0f97('0xa'));var moment=require(_0x0f97('0xb'));var validateJwt=expressJwt({'secret':config[_0x0f97('0xc')][_0x0f97('0xd')]});var userAttributes=['id',_0x0f97('0xe'),_0x0f97('0xf'),_0x0f97('0x10'),'internal','email',_0x0f97('0x11'),'permissions',_0x0f97('0x12'),_0x0f97('0x13'),_0x0f97('0x14'),'mailPause',_0x0f97('0x15'),'smsPause',_0x0f97('0x16'),_0x0f97('0x17'),_0x0f97('0x18'),_0x0f97('0x19'),_0x0f97('0x1a'),'crudPermissions',_0x0f97('0x1b'),_0x0f97('0x1c'),_0x0f97('0x1d'),_0x0f97('0x1e'),_0x0f97('0x1f'),_0x0f97('0x20'),_0x0f97('0x21'),'phoneBarEnableDtmfTone','phoneBarEnableSettings',_0x0f97('0x22'),_0x0f97('0x23'),_0x0f97('0x24'),_0x0f97('0x25'),'hotdesk','interface',_0x0f97('0x26'),_0x0f97('0x27'),_0x0f97('0x28')];exports[_0x0f97('0x29')]=function(){return this[_0x0f97('0x2a')](!![])[_0x0f97('0x2b')](function(_0x5059ad,_0x54717b,_0x35a341){if(_0x5059ad[_0x0f97('0x2c')]){_0x35a341();}else{return db[_0x0f97('0x2d')][_0x0f97('0x2e')]({'where':{'id':_0x5059ad[_0x0f97('0x2f')]['id']},'attributes':['id',_0x0f97('0x30'),'disposition'],'raw':!![]})[_0x0f97('0x31')](function(_0x15a1ef){if(_0x15a1ef&&_0x15a1ef[_0x0f97('0x30')]){return _0x54717b[_0x0f97('0x32')](_0x15a1ef[_0x0f97('0x33')]===_0x0f97('0x34')?0x195:0x193)[_0x0f97('0x35')]({'message':_0x15a1ef['disposition']===_0x0f97('0x34')?_0x0f97('0x36'):_0x0f97('0x37')});}else{_0x35a341();}})['catch'](function(_0x31d384){_0x35a341(_0x31d384);});}});};exports[_0x0f97('0x2a')]=function isAuthenticated(_0x4ec6d0){return compose()[_0x0f97('0x2b')](function(_0x15df5c,_0x4ef5bc,_0x489e1e){var _0x51aa82;if(_0x15df5c[_0x0f97('0x38')][_0x0f97('0x39')]){if(_['startsWith'](_0x15df5c[_0x0f97('0x38')][_0x0f97('0x39')],_0x0f97('0x3a'))){var _0x30d33d=basicAuth(_0x15df5c);db[_0x0f97('0x3b')][_0x0f97('0x3c')]({'where':{'name':_0x30d33d[_0x0f97('0x10')]}})[_0x0f97('0x31')](function(_0x1e688d){if(!_0x1e688d||!_0x1e688d[_0x0f97('0x3d')](_0x30d33d[_0x0f97('0x3e')])){return _0x4ef5bc['status'](0x191)[_0x0f97('0x35')]({'message':_0x0f97('0x3f')});}_0x15df5c[_0x0f97('0x2c')]={'id':_0x1e688d['id']};_0x489e1e();})[_0x0f97('0x40')](function(_0xc2ed81){_0x489e1e(_0xc2ed81);});}else if(_[_0x0f97('0x41')](_0x15df5c[_0x0f97('0x38')][_0x0f97('0x39')],'Bearer')){validateJwt(_0x15df5c,_0x4ef5bc,_0x489e1e);}else{if(_0x4ec6d0){_0x489e1e();}else{return _0x4ef5bc['status'](0x193)[_0x0f97('0x35')]({'message':_0x0f97('0x42')});}}}else if(_0x15df5c[_0x0f97('0x43')][_0x0f97('0x44')]){try{var _0x25bd0e={'audience':hardwareConf[_0x0f97('0x45')](),'issuer':hardwareConf[_0x0f97('0x45')]()};verifyJwt(_0x15df5c[_0x0f97('0x43')][_0x0f97('0x44')],_0x25bd0e)[_0x0f97('0x31')](function(_0x4107ac){return db['User'][_0x0f97('0x3c')]({'where':{'id':_0x4107ac[_0x0f97('0x46')]}})[_0x0f97('0x31')](function(_0x416495){_0x51aa82=_0x416495;return db[_0x0f97('0x47')]['findOne']({'where':{'id':0x1},'attributes':[_0x0f97('0x48'),'blockDuration'],'raw':!![]});})[_0x0f97('0x31')](function(_0x5dc775){if(!_0x51aa82||!_[_0x0f97('0x49')](_0x51aa82[_0x0f97('0x4a')],_0x4107ac[_0x0f97('0x4b')])){return _0x4ef5bc[_0x0f97('0x32')](0x191)[_0x0f97('0x35')]({'message':'API\x20access\x20key\x20is\x20not\x20valid\x20anymore'});}if(_0x51aa82['disabled']){return _0x4ef5bc[_0x0f97('0x32')](0x191)[_0x0f97('0x35')]({'message':'Invalid\x20API\x20access\x20key'});}if(_0x51aa82[_0x0f97('0x4c')]){if(_0x5dc775[_0x0f97('0x4d')]>0x0){if(moment(_0x51aa82[_0x0f97('0x4e')])[_0x0f97('0x4f')](_0x5dc775['blockDuration'],_0x0f97('0x50'))>moment()){return _0x4ef5bc[_0x0f97('0x32')](0x191)[_0x0f97('0x35')]({'message':_0x0f97('0x51')});}}else{return _0x4ef5bc[_0x0f97('0x32')](0x191)['json']({'message':_0x0f97('0x51')});}}_0x15df5c[_0x0f97('0x2c')]={'id':_0x51aa82['id']};_0x489e1e();});})[_0x0f97('0x40')](function(){return _0x4ef5bc[_0x0f97('0x32')](0x191)[_0x0f97('0x35')]({'message':_0x0f97('0x51')});});}catch(_0x50be3d){_0x489e1e(_0x50be3d);}}else if(_0x4ec6d0){_0x489e1e();}else{return _0x4ef5bc['status'](0x193)[_0x0f97('0x35')]({'message':_0x0f97('0x42')});}})[_0x0f97('0x2b')](function(_0x570700,_0x19b24e,_0xb24a15){if(_0x570700[_0x0f97('0x2c')]){db['User'][_0x0f97('0x3c')]({'where':{'id':_0x570700[_0x0f97('0x2c')]['id']},'attributes':userAttributes})[_0x0f97('0x31')](function(_0x679aea){if(!_0x679aea){return _0x19b24e[_0x0f97('0x32')](0x194)[_0x0f97('0x35')]({'message':_0x0f97('0x52')});}_0x570700[_0x0f97('0x2c')]=_0x679aea;_0xb24a15();})[_0x0f97('0x40')](function(_0x79aa92){_0xb24a15(_0x79aa92);});}else if(_0x4ec6d0){_0xb24a15();}else{return _0x19b24e[_0x0f97('0x32')](0x194)['json']({'message':_0x0f97('0x53')});}});};exports[_0x0f97('0x54')]=function canUpdate(){return compose()['use'](function(_0x299566,_0x57269c,_0x153777){return licenseUtil[_0x0f97('0x55')]()[_0x0f97('0x31')](function(_0x5934b1){if(_0x5934b1['update']){_0x153777();}else{return _0x57269c[_0x0f97('0x32')](0x193)[_0x0f97('0x35')]({'message':_0x0f97('0x56')});}})[_0x0f97('0x40')](function(_0x278a8c){_0x153777(_0x278a8c);});});};exports['isMiddleware']=function(_0x5962a4,_0x5c5e86,_0x401286){_0x5962a4[_0x0f97('0x57')]=!![];return _0x401286();};exports[_0x0f97('0x58')]=function signToken(_0x2a5f07){return signJwt(_0x2a5f07);};exports[_0x0f97('0x59')]=function(_0x2b19a9,_0xd9f44b){if(!_0x2b19a9[_0x0f97('0x2c')]){return _0xd9f44b['status'](0x194)[_0x0f97('0x35')]({'message':'It\x20looks\x20like\x20you\x20aren\x27t\x20logged\x20in,\x20please\x20try\x20again.'});}var _0x16ef4d={'payload':{'id':_0x2b19a9[_0x0f97('0x2c')]['id'],'role':_0x2b19a9[_0x0f97('0x2c')]['role']},'options':{'expiresIn':0x15180}};return signJwt(_0x16ef4d)['then'](function(_0x3bbdbc){_0xd9f44b[_0x0f97('0x5a')](_0x0f97('0x5b'),_0x3bbdbc);_0xd9f44b['redirect']('/dashboards/general');})['catch'](function(_0xa32a1d){return _0xd9f44b[_0x0f97('0x32')](0x1f4)[_0x0f97('0x5c')](_0xa32a1d);});};exports[_0x0f97('0x5d')]=function(_0x13e08c){if(_[_0x0f97('0x5e')](_0x13e08c[_0x0f97('0x4a')])||_[_0x0f97('0x5e')](_0x13e08c[_0x0f97('0x5f')])){return null;}else{return createJwt(_0x13e08c);}};exports[_0x0f97('0x60')]=function(_0x55eba){_0x55eba['apiKeyNonce']=generateNonce();_0x55eba[_0x0f97('0x5f')]=generateIssuedAt();return createJwt(_0x55eba);};exports['regenerateApiKey']=function(_0x5480e1,_0x408c5f){var _0x5d0fec=_0x5480e1[_0x0f97('0x43')][_0x0f97('0x44')];if(_0x5d0fec){var _0x31929a={'nonce':_0x408c5f[_0x0f97('0x4a')],'iat':_0x408c5f[_0x0f97('0x5f')],'audience':hardwareConf['getUuid'](),'issuer':hardwareConf['getUuid']()};return verifyJwt(_0x5d0fec,_0x31929a)[_0x0f97('0x31')](function(){return generateApiKey(_0x408c5f);});}else{throw{'message':_0x0f97('0x61')};}};exports['validatePasswordPattern']=function(_0x1a5d99){var _0x2a29ff=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(!_0x2a29ff[_0x0f97('0x62')](_0x1a5d99))throw new db[(_0x0f97('0x63'))]['ValidationError'](_0x0f97('0x64'));return;};exports[_0x0f97('0x65')]=function(_0x376880,_0xcf9bfc,_0x185238){var _0x2a30b1=encryptor[_0x0f97('0x66')](_0xcf9bfc)[_0x0f97('0x67')](',');for(var _0x2c8a73=0x0;_0x2c8a73<_0x185238;_0x2c8a73++){if(!_0x2a30b1[_0x2c8a73])break;if(_0x376880[_0x0f97('0x68')]()===_0x2a30b1[_0x2c8a73][_0x0f97('0x68')]()){var _0x736610=util[_0x0f97('0x69')](_0x0f97('0x6a'),_0x185238);if(_0x185238===0x1){_0x736610='The\x20password\x20must\x20be\x20different\x20from\x20the\x20last\x20one.\x20Please\x20choose\x20another\x20one.';}throw new db[(_0x0f97('0x63'))]['ValidationError'](_0x736610);}}return;};exports[_0x0f97('0x6b')]=function(_0x21ae61,_0x19484d){var _0x5716c5=_0x19484d?encryptor[_0x0f97('0x66')](_0x19484d)[_0x0f97('0x67')](','):[];if(_0x5716c5[_0x0f97('0x6c')]===0x5){_0x5716c5['splice'](-0x1,0x1);}_0x5716c5['unshift'](_0x21ae61);return encryptor['encryptString'](_0x5716c5['join'](','));};function signJwt(_0x375285){var _0x6f08c1=BPromise[_0x0f97('0x6d')](jwt['sign'],{'context':jwt});var _0x3e4a26=_0x375285['secret']||config[_0x0f97('0xc')][_0x0f97('0xd')];return new BPromise(function(_0x20890c,_0x8410d8){_0x6f08c1(_0x375285[_0x0f97('0x6e')],_0x3e4a26,_0x375285[_0x0f97('0x6f')])[_0x0f97('0x31')](function(_0x10a44f){_0x20890c(_0x10a44f);})[_0x0f97('0x40')](function(_0x59a646){_0x8410d8(_0x59a646);});});}function verifyJwt(_0x2e2103,_0xbd80c1,_0x406210){var _0x9c4705=BPromise[_0x0f97('0x6d')](jwt[_0x0f97('0x70')],{'context':jwt});var _0x47d67=_0x406210||config[_0x0f97('0xc')]['session'];return new BPromise(function(_0x40b7d6,_0xddbd8d){_0x9c4705(_0x2e2103,_0x47d67,_0xbd80c1)['then'](function(_0x35d089){_0x40b7d6(_0x35d089);})[_0x0f97('0x40')](function(_0xc744ed){_0xddbd8d(_0xc744ed);});});}function generateNonce(){return crypto[_0x0f97('0x71')](0x10)['toString'](_0x0f97('0x72'));}function generateIssuedAt(){return Math[_0x0f97('0x73')](Date[_0x0f97('0x74')]()/0x3e8)[_0x0f97('0x75')]();}function createJwt(_0x320b96){var _0x27d98c={'payload':{'iat':_0x320b96[_0x0f97('0x5f')],'nonce':_0x320b96[_0x0f97('0x4a')]},'options':{'algorithm':_0x0f97('0x76'),'subject':_0x320b96['id'][_0x0f97('0x75')](),'issuer':hardwareConf[_0x0f97('0x45')](),'audience':hardwareConf[_0x0f97('0x45')]()}};return signJwt(_0x27d98c)[_0x0f97('0x31')](function(_0x2fa000){return{'iat':_0x320b96['apiKeyIat'],'nonce':_0x320b96[_0x0f97('0x4a')],'token':_0x2fa000};});}
\ No newline at end of file
+var _0x9c44=['showWebBar','lastLoginAt','crudPermissions','allowmessenger','alias','phoneBarAutoAnswer','phoneBarAutoAnswerDelay','phoneBarDnd','phoneBarEnableRecording','phoneBarEnableDtmfTone','phoneBarEnableSettings','phoneBarExpires','phoneBarRemoteControl','phoneBarRemoteControlPort','hotdesk','interface','userProfileId','settingsEnabled','wssPort','downloadAttachments','ignorePauseForPreviewCalls','selectRecallMeCampaign','chatAutoanswerDelay','emailAutoanswerDelay','smsAutoanswer','smsAutoanswerDelay','openchannelAutoanswer','openchannelAutoanswerDelay','faxAutoanswer','faxAutoanswerDelay','whatsappAutoanswer','whatsappAutoanswerDelay','user','ChatInteraction','findOne','params','then','status','disposition','unmanaged','json','Unmanaged.','catch','isAuthenticated','headers','authorization','startsWith','Basic','authenticate','pass','Wrong\x20credentials.','Bearer','Unknown\x20authorization\x20format','apikey','getUuid','User','find','sub','Setting','allowedLoginAttempts','isEqual','apiKeyNonce','API\x20access\x20key\x20is\x20not\x20valid\x20anymore','Invalid\x20API\x20access\x20key','blocked','blockDuration','blockedAt','add','minutes','use','User\x20not\x20found.','User\x20object\x20not\x20found.','canUpdate','getLicense','update','Forbidden','isWebrtcLicence','webrtc','isMiddleware','setTokenCookie','cookie','motion.token','redirect','/dashboards/general','send','retrieveApiKey','isNil','apiKeyIat','generateApiKey','regenerateApiKey','Please\x20use\x20the\x20previous\x20API\x20access\x20key\x20to\x20generate\x20a\x20new\x20one','test','Sequelize','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','decryptString','split','toLowerCase','format','The\x20password\x20must\x20be\x20different\x20from\x20the\x20last\x20one.\x20Please\x20choose\x20another\x20one.','updatePasswordsHistory','length','unshift','encryptString','sign','options','promisify','toString','hex','floor','now','HS512','../../config/license/hardware','../../config/license/util','../encryptor','lodash','jsonwebtoken','express-jwt','crypto','util','moment','secrets','session','role','name','internal','email','userpic','voicePause','chatPause','faxPause','smsPause'];(function(_0x4c260a,_0x148241){var _0x17bbdd=function(_0x4f3e9f){while(--_0x4f3e9f){_0x4c260a['push'](_0x4c260a['shift']());}};_0x17bbdd(++_0x148241);}(_0x9c44,0x178));var _0x49c4=function(_0x3d42d8,_0x4cffaa){_0x3d42d8=_0x3d42d8-0x0;var _0x27fc41=_0x9c44[_0x3d42d8];return _0x27fc41;};'use strict';var db=require('../../mysqldb')['db'];var config=require('../../config/environment');var hardwareConf=require(_0x49c4('0x0'));var licenseUtil=require(_0x49c4('0x1'));var encryptor=require(_0x49c4('0x2'));var _=require(_0x49c4('0x3'));var jwt=require(_0x49c4('0x4'));var expressJwt=require(_0x49c4('0x5'));var compose=require('composable-middleware');var basicAuth=require('basic-auth');var crypto=require(_0x49c4('0x6'));var BPromise=require('bluebird');var util=require(_0x49c4('0x7'));var moment=require(_0x49c4('0x8'));var validateJwt=expressJwt({'secret':config[_0x49c4('0x9')][_0x49c4('0xa')]});var userAttributes=['id',_0x49c4('0xb'),'fullname',_0x49c4('0xc'),_0x49c4('0xd'),_0x49c4('0xe'),_0x49c4('0xf'),'permissions','md5secret',_0x49c4('0x10'),_0x49c4('0x11'),'mailPause',_0x49c4('0x12'),_0x49c4('0x13'),'openchannelPause','pauseType',_0x49c4('0x14'),_0x49c4('0x15'),'lastPauseAt',_0x49c4('0x16'),_0x49c4('0x17'),'passwordResetAt',_0x49c4('0x18'),_0x49c4('0x19'),_0x49c4('0x1a'),_0x49c4('0x1b'),_0x49c4('0x1c'),_0x49c4('0x1d'),_0x49c4('0x1e'),_0x49c4('0x1f'),'phoneBarPrefixRequired',_0x49c4('0x20'),_0x49c4('0x21'),_0x49c4('0x22'),_0x49c4('0x23'),_0x49c4('0x24'),'privacyEnabled',_0x49c4('0x25'),_0x49c4('0x26'),'downloadVoiceRecordings','downloadOmnichannelInteractions',_0x49c4('0x27'),_0x49c4('0x28'),_0x49c4('0x29'),'chatAutoanswer',_0x49c4('0x2a'),'emailAutoanswer',_0x49c4('0x2b'),_0x49c4('0x2c'),_0x49c4('0x2d'),_0x49c4('0x2e'),_0x49c4('0x2f'),_0x49c4('0x30'),_0x49c4('0x31'),_0x49c4('0x32'),_0x49c4('0x33')];exports['isChatInteractionAuthorized']=function(){return this['isAuthenticated'](!![])['use'](function(_0x1c99b1,_0x4f0b62,_0x592bb8){if(_0x1c99b1[_0x49c4('0x34')]){_0x592bb8();}else{return db[_0x49c4('0x35')][_0x49c4('0x36')]({'where':{'id':_0x1c99b1[_0x49c4('0x37')]['id']},'attributes':['id','closed','disposition'],'raw':!![]})[_0x49c4('0x38')](function(_0x9cb797){if(_0x9cb797&&_0x9cb797['closed']){return _0x4f0b62[_0x49c4('0x39')](_0x9cb797[_0x49c4('0x3a')]===_0x49c4('0x3b')?0x195:0x193)[_0x49c4('0x3c')]({'message':_0x9cb797['disposition']==='unmanaged'?_0x49c4('0x3d'):'Forbidden.'});}else{_0x592bb8();}})[_0x49c4('0x3e')](function(_0x3852b2){_0x592bb8(_0x3852b2);});}});};exports[_0x49c4('0x3f')]=function isAuthenticated(_0x372a47){return compose()['use'](function(_0x889909,_0x2b2793,_0x46e04d){var _0x4f28a2;if(_0x889909[_0x49c4('0x40')][_0x49c4('0x41')]){if(_[_0x49c4('0x42')](_0x889909[_0x49c4('0x40')][_0x49c4('0x41')],_0x49c4('0x43'))){var _0x46f7ea=basicAuth(_0x889909);db['User']['find']({'where':{'name':_0x46f7ea['name']}})[_0x49c4('0x38')](function(_0x7ee704){if(!_0x7ee704||!_0x7ee704[_0x49c4('0x44')](_0x46f7ea[_0x49c4('0x45')])){return _0x2b2793[_0x49c4('0x39')](0x191)['json']({'message':_0x49c4('0x46')});}_0x889909[_0x49c4('0x34')]={'id':_0x7ee704['id']};_0x46e04d();})[_0x49c4('0x3e')](function(_0x24bba9){_0x46e04d(_0x24bba9);});}else if(_['startsWith'](_0x889909['headers'][_0x49c4('0x41')],_0x49c4('0x47'))){validateJwt(_0x889909,_0x2b2793,_0x46e04d);}else{if(_0x372a47){_0x46e04d();}else{return _0x2b2793[_0x49c4('0x39')](0x193)[_0x49c4('0x3c')]({'message':_0x49c4('0x48')});}}}else if(_0x889909['query'][_0x49c4('0x49')]){try{var _0x84c621={'audience':hardwareConf[_0x49c4('0x4a')](),'issuer':hardwareConf['getUuid']()};verifyJwt(_0x889909['query'][_0x49c4('0x49')],_0x84c621)[_0x49c4('0x38')](function(_0x3bec0a){return db[_0x49c4('0x4b')][_0x49c4('0x4c')]({'where':{'id':_0x3bec0a[_0x49c4('0x4d')]}})[_0x49c4('0x38')](function(_0x27ef5f){_0x4f28a2=_0x27ef5f;return db[_0x49c4('0x4e')]['findOne']({'where':{'id':0x1},'attributes':[_0x49c4('0x4f'),'blockDuration'],'raw':!![]});})[_0x49c4('0x38')](function(_0x349791){if(!_0x4f28a2||!_[_0x49c4('0x50')](_0x4f28a2[_0x49c4('0x51')],_0x3bec0a['nonce'])){return _0x2b2793[_0x49c4('0x39')](0x191)[_0x49c4('0x3c')]({'message':_0x49c4('0x52')});}if(_0x4f28a2['disabled']){return _0x2b2793[_0x49c4('0x39')](0x191)[_0x49c4('0x3c')]({'message':_0x49c4('0x53')});}if(_0x4f28a2[_0x49c4('0x54')]){if(_0x349791[_0x49c4('0x55')]>0x0){if(moment(_0x4f28a2[_0x49c4('0x56')])[_0x49c4('0x57')](_0x349791[_0x49c4('0x55')],_0x49c4('0x58'))>moment()){return _0x2b2793[_0x49c4('0x39')](0x191)[_0x49c4('0x3c')]({'message':'Invalid\x20API\x20access\x20key'});}}else{return _0x2b2793[_0x49c4('0x39')](0x191)[_0x49c4('0x3c')]({'message':_0x49c4('0x53')});}}_0x889909[_0x49c4('0x34')]={'id':_0x4f28a2['id']};_0x46e04d();});})[_0x49c4('0x3e')](function(){return _0x2b2793[_0x49c4('0x39')](0x191)[_0x49c4('0x3c')]({'message':_0x49c4('0x53')});});}catch(_0x248c0a){_0x46e04d(_0x248c0a);}}else if(_0x372a47){_0x46e04d();}else{return _0x2b2793[_0x49c4('0x39')](0x193)[_0x49c4('0x3c')]({'message':_0x49c4('0x48')});}})[_0x49c4('0x59')](function(_0x4e38bc,_0x212366,_0x49829e){if(_0x4e38bc[_0x49c4('0x34')]){db[_0x49c4('0x4b')][_0x49c4('0x4c')]({'where':{'id':_0x4e38bc[_0x49c4('0x34')]['id']},'attributes':userAttributes})[_0x49c4('0x38')](function(_0x281b83){if(!_0x281b83){return _0x212366['status'](0x194)['json']({'message':_0x49c4('0x5a')});}_0x4e38bc[_0x49c4('0x34')]=_0x281b83;_0x49829e();})[_0x49c4('0x3e')](function(_0x117151){_0x49829e(_0x117151);});}else if(_0x372a47){_0x49829e();}else{return _0x212366['status'](0x194)[_0x49c4('0x3c')]({'message':_0x49c4('0x5b')});}});};exports[_0x49c4('0x5c')]=function canUpdate(){return compose()[_0x49c4('0x59')](function(_0x81a674,_0x3bde49,_0x1a9593){return licenseUtil[_0x49c4('0x5d')]()[_0x49c4('0x38')](function(_0x5640d3){if(_0x5640d3[_0x49c4('0x5e')]){_0x1a9593();}else{return _0x3bde49['status'](0x193)[_0x49c4('0x3c')]({'message':_0x49c4('0x5f')});}})[_0x49c4('0x3e')](function(_0x258abe){_0x1a9593(_0x258abe);});});};exports[_0x49c4('0x60')]=function isWebrtcLicence(){return compose()['use'](function(_0x592e8e,_0x15b674,_0x384862){return licenseUtil[_0x49c4('0x5d')]()[_0x49c4('0x38')](function(_0x5d4790){if(_0x5d4790[_0x49c4('0x61')]){_0x384862();}else{return _0x15b674['status'](0x193)[_0x49c4('0x3c')]({'message':'Forbidden'});}})[_0x49c4('0x3e')](function(_0x906d3){_0x384862(_0x906d3);});});};exports[_0x49c4('0x62')]=function(_0x27adfe,_0x2d8087,_0x30bea5){_0x27adfe[_0x49c4('0x62')]=!![];return _0x30bea5();};exports['signToken']=function signToken(_0x3b731f){return signJwt(_0x3b731f);};exports[_0x49c4('0x63')]=function(_0x4a5c34,_0x1e1ac4){if(!_0x4a5c34[_0x49c4('0x34')]){return _0x1e1ac4[_0x49c4('0x39')](0x194)[_0x49c4('0x3c')]({'message':'It\x20looks\x20like\x20you\x20aren\x27t\x20logged\x20in,\x20please\x20try\x20again.'});}var _0x5d8bf0={'payload':{'id':_0x4a5c34[_0x49c4('0x34')]['id'],'role':_0x4a5c34['user'][_0x49c4('0xb')]},'options':{'expiresIn':0x15180}};return signJwt(_0x5d8bf0)[_0x49c4('0x38')](function(_0x3811b2){_0x1e1ac4[_0x49c4('0x64')](_0x49c4('0x65'),_0x3811b2);_0x1e1ac4[_0x49c4('0x66')](_0x49c4('0x67'));})['catch'](function(_0x1f26c2){return _0x1e1ac4[_0x49c4('0x39')](0x1f4)[_0x49c4('0x68')](_0x1f26c2);});};exports[_0x49c4('0x69')]=function(_0x17ef75){if(_[_0x49c4('0x6a')](_0x17ef75[_0x49c4('0x51')])||_[_0x49c4('0x6a')](_0x17ef75[_0x49c4('0x6b')])){return null;}else{return createJwt(_0x17ef75);}};exports[_0x49c4('0x6c')]=function(_0x5b822f){_0x5b822f['apiKeyNonce']=generateNonce();_0x5b822f[_0x49c4('0x6b')]=generateIssuedAt();return createJwt(_0x5b822f);};exports[_0x49c4('0x6d')]=function(_0x527e74,_0x59a8bc){var _0x77163d=_0x527e74['query']['apikey'];if(_0x77163d){var _0x3208c2={'nonce':_0x59a8bc[_0x49c4('0x51')],'iat':_0x59a8bc[_0x49c4('0x6b')],'audience':hardwareConf[_0x49c4('0x4a')](),'issuer':hardwareConf[_0x49c4('0x4a')]()};return verifyJwt(_0x77163d,_0x3208c2)[_0x49c4('0x38')](function(){return generateApiKey(_0x59a8bc);});}else{throw{'message':_0x49c4('0x6e')};}};exports['validatePasswordPattern']=function(_0x859dde){var _0xcc6a2b=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(!_0xcc6a2b[_0x49c4('0x6f')](_0x859dde))throw new db[(_0x49c4('0x70'))][(_0x49c4('0x71'))](_0x49c4('0x72'));return;};exports['validatePasswordHistory']=function(_0x5c7ddd,_0x1ef0c1,_0x155c43){var _0x2a6308=encryptor[_0x49c4('0x73')](_0x1ef0c1)[_0x49c4('0x74')](',');for(var _0x6b2592=0x0;_0x6b2592<_0x155c43;_0x6b2592++){if(!_0x2a6308[_0x6b2592])break;if(_0x5c7ddd[_0x49c4('0x75')]()===_0x2a6308[_0x6b2592]['toLowerCase']()){var _0x45d715=util[_0x49c4('0x76')]('The\x20password\x20must\x20be\x20different\x20from\x20the\x20previous\x20%d\x20passwords.\x20Please\x20choose\x20another\x20one.',_0x155c43);if(_0x155c43===0x1){_0x45d715=_0x49c4('0x77');}throw new db['Sequelize'][(_0x49c4('0x71'))](_0x45d715);}}return;};exports[_0x49c4('0x78')]=function(_0x9eaa84,_0x2fe89a){var _0x845f7e=_0x2fe89a?encryptor[_0x49c4('0x73')](_0x2fe89a)[_0x49c4('0x74')](','):[];if(_0x845f7e[_0x49c4('0x79')]===0x5){_0x845f7e['splice'](-0x1,0x1);}_0x845f7e[_0x49c4('0x7a')](_0x9eaa84);return encryptor[_0x49c4('0x7b')](_0x845f7e['join'](','));};function signJwt(_0x10dec7){var _0x299e74=BPromise['promisify'](jwt[_0x49c4('0x7c')],{'context':jwt});var _0x42e0e6=_0x10dec7['secret']||config['secrets']['session'];return new BPromise(function(_0x513879,_0xc43386){_0x299e74(_0x10dec7['payload'],_0x42e0e6,_0x10dec7[_0x49c4('0x7d')])[_0x49c4('0x38')](function(_0x515240){_0x513879(_0x515240);})[_0x49c4('0x3e')](function(_0xdb2b33){_0xc43386(_0xdb2b33);});});}function verifyJwt(_0x5ac9f0,_0x34272f,_0x3dcf4c){var _0x167e84=BPromise[_0x49c4('0x7e')](jwt['verify'],{'context':jwt});var _0x431921=_0x3dcf4c||config[_0x49c4('0x9')][_0x49c4('0xa')];return new BPromise(function(_0x20e97d,_0x5d3375){_0x167e84(_0x5ac9f0,_0x431921,_0x34272f)[_0x49c4('0x38')](function(_0x4a93bc){_0x20e97d(_0x4a93bc);})['catch'](function(_0x58259d){_0x5d3375(_0x58259d);});});}function generateNonce(){return crypto['randomBytes'](0x10)[_0x49c4('0x7f')](_0x49c4('0x80'));}function generateIssuedAt(){return Math[_0x49c4('0x81')](Date[_0x49c4('0x82')]()/0x3e8)['toString']();}function createJwt(_0x4daa6d){var _0x340523={'payload':{'iat':_0x4daa6d[_0x49c4('0x6b')],'nonce':_0x4daa6d[_0x49c4('0x51')]},'options':{'algorithm':_0x49c4('0x83'),'subject':_0x4daa6d['id'][_0x49c4('0x7f')](),'issuer':hardwareConf[_0x49c4('0x4a')](),'audience':hardwareConf[_0x49c4('0x4a')]()}};return signJwt(_0x340523)[_0x49c4('0x38')](function(_0x4d49e0){return{'iat':_0x4daa6d[_0x49c4('0x6b')],'nonce':_0x4daa6d['apiKeyNonce'],'token':_0x4d49e0};});}
\ No newline at end of file