5820fcb67bf24a4d6a129ef130563870f676e6e1
[motion2.git] / server / config / license / util.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x2318=['grayReason','changed','disabled','uuid','User','role','sequelize','col','count','admin','user','users','telephones','forEach','pick','countBy','telephone','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','util','lodash','moment','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Breaking\x20license','License','find','then','catch','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','format','%s:%s:%s','parse','demo','machineUuid','getUuid','gray','deadline','days'];(function(_0x5608a3,_0x5b33c5){var _0x1ed50a=function(_0x959171){while(--_0x959171){_0x5608a3['push'](_0x5608a3['shift']());}};_0x1ed50a(++_0x5b33c5);}(_0x2318,0xcf));var _0x8231=function(_0x5d606a,_0x225ae2){_0x5d606a=_0x5d606a-0x0;var _0x13c724=_0x2318[_0x5d606a];return _0x13c724;};'use strict';var util=require(_0x8231('0x0'));var _=require(_0x8231('0x1'));var moment=require(_0x8231('0x2'));var BPromise=require('bluebird');var hardware=require(_0x8231('0x3'));var encryptor=require(_0x8231('0x4'));var db=require(_0x8231('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x8231('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':'2027-01-01T00:00:00.000Z','chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x8231('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x381fdb){return new BPromise(function(_0x9b14a3,_0x45d56d){return db[_0x8231('0x8')][_0x8231('0x9')](_['defaults'](_0x381fdb,{'raw':!![],'where':{'id':0x1}}))[_0x8231('0xa')](function(_0x8e8f59){return checkLicense(_0x8e8f59,null);})[_0x8231('0xa')](function(_0x58243d){_0x9b14a3(_0x58243d);return;})[_0x8231('0xb')](function(_0x5be268){_0x45d56d(_0x5be268);});});}function checkLicense(_0x2897fb,_0x4664de){if(!_0x2897fb){demoLicense['uuid']=_0x2897fb[_0x8231('0xc')];return demoLicense;}try{var _0x263fb8=_0x4664de||_0x2897fb[_0x8231('0xd')];if(_[_0x8231('0xe')](_0x263fb8)){throw new Error(_0x8231('0xf'));}var _0x39ab6f=_0x2897fb[_0x8231('0xc')];var _0x4931be=_0x2897fb[_0x8231('0x10')];var _0x49644c=_0x39ab6f[_0x8231('0x11')]('-')[0x4];var _0x1307ec=_0x39ab6f[_0x8231('0x11')]('-')[0x0];var _0x14935b=encryptor[_0x8231('0x12')](_0x263fb8,util[_0x8231('0x13')](_0x8231('0x14'),_0x49644c,_0x39ab6f,_0x1307ec));var _0x1b7bda=JSON[_0x8231('0x15')](_0x14935b);_0x1b7bda[_0x8231('0x16')]=![];_0x1b7bda['uuid']=_0x39ab6f;_0x1b7bda[_0x8231('0x17')]=hardware[_0x8231('0x18')]();if(_0x4931be){var _0x4345a=encryptor['decryptString'](_0x4931be);_0x1b7bda[_0x8231('0x19')]=_0x4345a;_0x1b7bda[_0x8231('0x1a')]=moment(_0x4345a)['add'](0x7,_0x8231('0x1b'))[_0x8231('0x13')]();_0x1b7bda[_0x8231('0x1c')]=_0x1b7bda['uuid']!=_0x1b7bda[_0x8231('0x17')]?_0x8231('0x1d'):_0x8231('0x1e');}return _0x1b7bda;}catch(_0x2c7828){breakingLicense[_0x8231('0x1f')]=_0x2897fb['data1'];breakingLicense['message']=_0x2c7828['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x2e7e51,_0x4342b0){getLicense()[_0x8231('0xa')](function(_0x37d136){return db[_0x8231('0x20')]['findAll']({'attributes':[_0x8231('0x21'),[db[_0x8231('0x22')]['fn']('COUNT',db[_0x8231('0x22')][_0x8231('0x23')](_0x8231('0x21'))),_0x8231('0x24')]],'group':'role','where':{'role':{'$or':[_0x8231('0x25'),_0x8231('0x26'),'telephone']}},'raw':!![]})[_0x8231('0xa')](function(_0x148765){var _0xd6c094={'user':_0x37d136[_0x8231('0x27')]||0x0,'telephone':_0x37d136[_0x8231('0x28')]||0x0};_0x148765[_0x8231('0x29')](function(_0xfd0935){var _0x2e1581=_0xfd0935[_0x8231('0x21')]==='admin'?'user':_0xfd0935[_0x8231('0x21')];_0xd6c094[_0x2e1581]-=_0xfd0935['count'];if(_0xd6c094[_0x2e1581]<0x0)_0xd6c094[_0x2e1581]=0x0;});_0x2e7e51(_0xd6c094);return;});})[_0x8231('0xb')](function(_0x2a4aa7){_0x4342b0(_0x2a4aa7);});});}function checkUserLimits(_0x4873d8){return new BPromise(function(_0x16610b,_0x273be0){getLimits()[_0x8231('0xa')](function(_0xf2c059){var _0x283544=_[_0x8231('0x2a')](_[_0x8231('0x2b')](_0x4873d8,'role'),[_0x8231('0x25'),_0x8231('0x26'),_0x8231('0x2c')]);var _0x5883c6=(_0x283544['admin']||0x0)+(_0x283544['user']||0x0);var _0x426025=_0x283544[_0x8231('0x2c')]||0x0;if(_0x5883c6>_0xf2c059[_0x8231('0x26')])return _0x273be0(_0x8231('0x2d'));if(_0x426025>_0xf2c059['telephone'])return _0x273be0(_0x8231('0x2e'));return _0x16610b();})['catch'](function(_0x40af47){_0x273be0(_0x40af47);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};