025c752573924cfe452334bd647c68003f7d801b
[motion2.git] / server / config / license / index.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 _0x0cce=['finally','getUuid','License','SERVICE\x20LICENSE\x20STARTED\x20%s','default','request-promise','bluebird','../../mysqldb','../../components/encryptor','license','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','version','GET','then','catch','data1','data2','active','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','encryptString','YYYY-MM-DD\x20HH:mm','diff','days','DEMO\x20START\x20AT\x20%s','error','message'];(function(_0x1233f8,_0x21238b){var _0x42f95c=function(_0x58b8e1){while(--_0x58b8e1){_0x1233f8['push'](_0x1233f8['shift']());}};_0x42f95c(++_0x21238b);}(_0x0cce,0x1f3));var _0xe0cc=function(_0x3e5608,_0x8b6979){_0x3e5608=_0x3e5608-0x0;var _0x4128d3=_0x0cce[_0x3e5608];return _0x4128d3;};'use strict';var util=require('util');var moment=require('moment');var rp=require(_0xe0cc('0x0'));var BPromise=require(_0xe0cc('0x1'));var pkginfo=require('pkginfo')(module,'version');var db=require(_0xe0cc('0x2'))['db'];var encryptor=require(_0xe0cc('0x3'));var hardware=require('./hardware');var logger=require('../logger')(_0xe0cc('0x4'));var HOST=_0xe0cc('0x5');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x3044cb){return new BPromise(function(_0x1cd200,_0x50a9c7){var _0x2d664a=util[_0xe0cc('0x6')](_0xe0cc('0x7'),HOST,_0x3044cb,module[_0xe0cc('0x8')]['version']);if(oldToken){_0x2d664a=util['format'](_0xe0cc('0x9'),HOST,_0x3044cb,module[_0xe0cc('0x8')][_0xe0cc('0xa')],oldToken);}var _0x563bab={'uri':_0x2d664a,'method':_0xe0cc('0xb'),'timeout':0xea60,'json':!![]};return rp(_0x563bab)[_0xe0cc('0xc')](function(_0x37b2e6){_0x1cd200(_0x37b2e6);})[_0xe0cc('0xd')](function(_0x3ba78d){_0x50a9c7(_0x3ba78d);});});}function manageLicense(_0x3ad13c,_0x117f0f){var _0x56415e=_0x117f0f['get']({'plain':!![]});if(!isOldTokenSent&&_0x56415e[_0xe0cc('0xe')]!==_0x3ad13c&&!_0x56415e[_0xe0cc('0xf')]){oldToken=_0x56415e[_0xe0cc('0xe')];}httpRequest(_0x3ad13c)[_0xe0cc('0xc')](function(_0x33904f){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x33904f[_0xe0cc('0x10')]){isOldTokenSent=![];if(!_0x56415e[_0xe0cc('0x4')]&&_0x56415e[_0xe0cc('0x4')]!=_0x33904f[_0xe0cc('0x4')]||_0x56415e[_0xe0cc('0x4')]&&_0x56415e['data2']){logger[_0xe0cc('0x11')](_0xe0cc('0x12'));}if(_0x56415e[_0xe0cc('0x4')]&&!_0x56415e[_0xe0cc('0xf')]&&_0x56415e[_0xe0cc('0x4')]!=_0x33904f['license']){logger[_0xe0cc('0x11')](_0xe0cc('0x13'));}if(_0x56415e[_0xe0cc('0x4')]&&!_0x56415e[_0xe0cc('0xf')]&&_0x56415e[_0xe0cc('0x4')]==_0x33904f[_0xe0cc('0x4')]){return _0x117f0f;}return _0x117f0f[_0xe0cc('0x14')]({'data1':_0x3ad13c,'data2':null,'license':_0x33904f[_0xe0cc('0x4')]});}else{if(_0x33904f[_0xe0cc('0x4')]||_0x56415e['license']){if(!_0x56415e[_0xe0cc('0xf')]){if(_0x56415e[_0xe0cc('0xe')]==_0x3ad13c){GRAY_PERIOD_REASON=_0xe0cc('0x15');logger[_0xe0cc('0x11')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0xe0cc('0x16');logger['info'](_0xe0cc('0x17'),_0x56415e[_0xe0cc('0xe')],_0x3ad13c);}logger[_0xe0cc('0x11')](_0xe0cc('0x18'),GRAY_PERIOD_REASON[_0xe0cc('0x19')](),moment()[_0xe0cc('0x6')]('YYYY-MM-DD\x20HH:mm'));return _0x117f0f[_0xe0cc('0x14')]({'data2':encryptor[_0xe0cc('0x1a')](moment()['format'](_0xe0cc('0x1b')))});}else{if(moment()[_0xe0cc('0x1c')](encryptor['decryptString'](_0x56415e[_0xe0cc('0xf')]),_0xe0cc('0x1d'))>DAYS){logger[_0xe0cc('0x11')](_0xe0cc('0x1e'),moment()['format'](_0xe0cc('0x1b')));isOldTokenSent=![];return _0x117f0f['update']({'data1':_0x3ad13c,'data2':null,'license':null});}}}else{if(_0x56415e[_0xe0cc('0xe')]!=_0x3ad13c){logger[_0xe0cc('0x11')](_0xe0cc('0x17'),_0x56415e[_0xe0cc('0xe')],_0x3ad13c);return _0x117f0f[_0xe0cc('0x14')]({'data1':_0x3ad13c,'data2':null,'license':null});}}}return _0x117f0f;})[_0xe0cc('0xc')](function(_0x16b686){_0x117f0f=_0x16b686;})[_0xe0cc('0xd')](function(_0x17dffe){logger[_0xe0cc('0x1f')](_0x17dffe[_0xe0cc('0x20')]);})[_0xe0cc('0x21')](function(){setTimeout(function(){manageLicense(hardware[_0xe0cc('0x22')](),_0x117f0f);},TIME);});}function defaultLicense(){var _0x21a5cc=hardware[_0xe0cc('0x22')]();if(_0x21a5cc){return db[_0xe0cc('0x23')]['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x21a5cc}})['spread'](function(_0x2e01a8,_0x282095){logger[_0xe0cc('0x11')](_0xe0cc('0x24'),_0x21a5cc);manageLicense(_0x21a5cc,_0x2e01a8);})['catch'](function(_0x3d206c){logger[_0xe0cc('0x1f')](_0x3d206c[_0xe0cc('0x20')]);});}}exports[_0xe0cc('0x25')]=defaultLicense;