Built motion from commit 0900f080.|2.5.45
[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 _0x9e4f=['exports','version','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','data1','data2','active','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','decryptString','days','DEMO\x20START\x20AT\x20%s','catch','error','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','moment','request-promise','pkginfo','../../mysqldb','./hardware','../logger','license','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s'];(function(_0xdb5036,_0x914c61){var _0x58fb12=function(_0x5deae1){while(--_0x5deae1){_0xdb5036['push'](_0xdb5036['shift']());}};_0x58fb12(++_0x914c61);}(_0x9e4f,0x129));var _0xf9e4=function(_0x7dc310,_0x31b4b4){_0x7dc310=_0x7dc310-0x0;var _0x2fa377=_0x9e4f[_0x7dc310];return _0x2fa377;};'use strict';var util=require(_0xf9e4('0x0'));var moment=require(_0xf9e4('0x1'));var rp=require(_0xf9e4('0x2'));var BPromise=require('bluebird');var pkginfo=require(_0xf9e4('0x3'))(module,'version');var db=require(_0xf9e4('0x4'))['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0xf9e4('0x5'));var logger=require(_0xf9e4('0x6'))(_0xf9e4('0x7'));var HOST=_0xf9e4('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x83541c){return new BPromise(function(_0x1dcb62,_0x32f628){var _0x410935=util[_0xf9e4('0x9')](_0xf9e4('0xa'),HOST,_0x83541c,module[_0xf9e4('0xb')][_0xf9e4('0xc')]);if(oldToken){_0x410935=util[_0xf9e4('0x9')](_0xf9e4('0xd'),HOST,_0x83541c,module[_0xf9e4('0xb')][_0xf9e4('0xc')],oldToken);}var _0x5f1c64={'uri':_0x410935,'method':_0xf9e4('0xe'),'timeout':0xea60,'json':!![]};return rp(_0x5f1c64)[_0xf9e4('0xf')](function(_0x5c6305){_0x1dcb62(_0x5c6305);})['catch'](function(_0x5a2219){_0x32f628(_0x5a2219);});});}function manageLicense(_0x1cedc8,_0xcc2789){var _0x5a0b8a=_0xcc2789['get']({'plain':!![]});if(!isOldTokenSent&&_0x5a0b8a[_0xf9e4('0x10')]!==_0x1cedc8&&!_0x5a0b8a[_0xf9e4('0x11')]){oldToken=_0x5a0b8a[_0xf9e4('0x10')];}httpRequest(_0x1cedc8)['then'](function(_0x500170){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x500170[_0xf9e4('0x12')]){isOldTokenSent=![];if(!_0x5a0b8a[_0xf9e4('0x7')]&&_0x5a0b8a[_0xf9e4('0x7')]!=_0x500170[_0xf9e4('0x7')]||_0x5a0b8a[_0xf9e4('0x7')]&&_0x5a0b8a[_0xf9e4('0x11')]){logger[_0xf9e4('0x13')](_0xf9e4('0x14'));}if(_0x5a0b8a[_0xf9e4('0x7')]&&!_0x5a0b8a['data2']&&_0x5a0b8a[_0xf9e4('0x7')]!=_0x500170[_0xf9e4('0x7')]){logger[_0xf9e4('0x13')](_0xf9e4('0x15'));}if(_0x5a0b8a['license']&&!_0x5a0b8a['data2']&&_0x5a0b8a[_0xf9e4('0x7')]==_0x500170['license']){return _0xcc2789;}return _0xcc2789[_0xf9e4('0x16')]({'data1':_0x1cedc8,'data2':null,'license':_0x500170[_0xf9e4('0x7')]});}else{if(_0x500170[_0xf9e4('0x7')]||_0x5a0b8a['license']){if(!_0x5a0b8a[_0xf9e4('0x11')]){if(_0x5a0b8a['data1']==_0x1cedc8){GRAY_PERIOD_REASON=_0xf9e4('0x17');logger[_0xf9e4('0x13')](_0xf9e4('0x18'));}else{GRAY_PERIOD_REASON=_0xf9e4('0x19');logger[_0xf9e4('0x13')](_0xf9e4('0x1a'),_0x5a0b8a['data1'],_0x1cedc8);}logger[_0xf9e4('0x13')](_0xf9e4('0x1b'),GRAY_PERIOD_REASON[_0xf9e4('0x1c')](),moment()['format'](_0xf9e4('0x1d')));return _0xcc2789['update']({'data2':encryptor[_0xf9e4('0x1e')](moment()[_0xf9e4('0x9')]('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()['diff'](encryptor[_0xf9e4('0x1f')](_0x5a0b8a['data2']),_0xf9e4('0x20'))>DAYS){logger['info'](_0xf9e4('0x21'),moment()[_0xf9e4('0x9')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0xcc2789[_0xf9e4('0x16')]({'data1':_0x1cedc8,'data2':null,'license':null});}}}else{if(_0x5a0b8a[_0xf9e4('0x10')]!=_0x1cedc8){logger[_0xf9e4('0x13')](_0xf9e4('0x1a'),_0x5a0b8a[_0xf9e4('0x10')],_0x1cedc8);return _0xcc2789[_0xf9e4('0x16')]({'data1':_0x1cedc8,'data2':null,'license':null});}}}return _0xcc2789;})[_0xf9e4('0xf')](function(_0x2082f4){_0xcc2789=_0x2082f4;})[_0xf9e4('0x22')](function(_0x44b62c){logger[_0xf9e4('0x23')](_0x44b62c[_0xf9e4('0x24')]);})[_0xf9e4('0x25')](function(){setTimeout(function(){manageLicense(hardware[_0xf9e4('0x26')](),_0xcc2789);},TIME);});}function defaultLicense(){var _0x364b78=hardware[_0xf9e4('0x26')]();if(_0x364b78){return db[_0xf9e4('0x27')][_0xf9e4('0x28')]({'where':{'id':0x1},'defaults':{'data1':_0x364b78}})[_0xf9e4('0x29')](function(_0x510bf7,_0x4be283){logger['info'](_0xf9e4('0x2a'),_0x364b78);manageLicense(_0x364b78,_0x510bf7);})[_0xf9e4('0x22')](function(_0x3798f6){logger[_0xf9e4('0x23')](_0x3798f6['message']);});}}exports[_0xf9e4('0x2b')]=defaultLicense;