Built motion from commit b4f7ded2.|2.0.69
[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 _0x9a6c=['admin','fullname','email','|uuid|','|machineUuid|','|name|','|email|','then','getFirstInterface','openIssue','Motion\x20License\x20Alert','Alert','get','active','data2','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','data1','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','uuid','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','YYYY-MM-DD\x20HH:mm','error','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','catch','crypto','moment','bluebird','pkginfo','version','../../mysqldb','./hardware','../logger','license','../../api/jira/jira.controller','www.xcallymotion.com','format','GET','application/json','request','setEncoding','data','end','parse','createCipher','aes-256-ctr','secrets','session','update','utf8','final','base64','||FIELD||VALUE||\x0a','User','findOne'];(function(_0x486f4a,_0x478dc7){var _0x135d99=function(_0x434008){while(--_0x434008){_0x486f4a['push'](_0x486f4a['shift']());}};_0x135d99(++_0x478dc7);}(_0x9a6c,0x127));var _0xc9a6=function(_0x2cf2e9,_0xd58ea1){_0x2cf2e9=_0x2cf2e9-0x0;var _0xd3670d=_0x9a6c[_0x2cf2e9];return _0xd3670d;};'use strict';var util=require('util');var https=require('https');var crypto=require(_0xc9a6('0x0'));var moment=require(_0xc9a6('0x1'));var BPromise=require(_0xc9a6('0x2'));var pkginfo=require(_0xc9a6('0x3'))(module,_0xc9a6('0x4'));var db=require(_0xc9a6('0x5'))['db'];var config=require('../environment');var hardware=require(_0xc9a6('0x6'));var logger=require(_0xc9a6('0x7'))(_0xc9a6('0x8'));var jira=require(_0xc9a6('0x9'));var HOST=_0xc9a6('0xa');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var ADMIN;function httpRequest(_0x1a8aea){return new BPromise(function(_0x148544,_0x4abf3b){var _0x2fbd89={'host':HOST,'port':0x1bb,'path':util[_0xc9a6('0xb')]('/api/servers/%s/check?version=%s',_0x1a8aea,module['exports']['version']),'method':_0xc9a6('0xc'),'timeout':0xea60,'headers':{'Content-Type':_0xc9a6('0xd')}};var _0x5f265d=https[_0xc9a6('0xe')](_0x2fbd89,function(_0x113c17){_0x113c17[_0xc9a6('0xf')]('utf8');var _0x509083='';_0x113c17['on'](_0xc9a6('0x10'),function(_0x384b66){_0x509083+=_0x384b66;});_0x113c17['on'](_0xc9a6('0x11'),function(){try{_0x148544(JSON[_0xc9a6('0x12')](_0x509083));}catch(_0x25fa9c){_0x4abf3b(_0x25fa9c);}});});_0x5f265d['on']('error',_0x4abf3b);_0x5f265d[_0xc9a6('0x11')]();});}function encryptDate(_0x2e170a){var _0x29cf37=crypto[_0xc9a6('0x13')](_0xc9a6('0x14'),config[_0xc9a6('0x15')][_0xc9a6('0x16')]);var _0x16f1e6=_0x29cf37[_0xc9a6('0x17')](_0x2e170a,_0xc9a6('0x18'),'base64');_0x16f1e6+=_0x29cf37[_0xc9a6('0x19')](_0xc9a6('0x1a'));return _0x16f1e6;}function decryptDate(_0x465024){var _0x5e046d=crypto['createDecipher']('aes-256-ctr',config[_0xc9a6('0x15')][_0xc9a6('0x16')]);var _0x2f45ba=_0x5e046d['update'](_0x465024,_0xc9a6('0x1a'),_0xc9a6('0x18'));_0x2f45ba+=_0x5e046d[_0xc9a6('0x19')]('utf8');return _0x2f45ba;}function sendJiraAlert(_0x491195,_0x492f5c,_0x2484c2){var _0x21ccf3=_0xc9a6('0x1b');return db[_0xc9a6('0x1c')][_0xc9a6('0x1d')]({'where':{'role':_0xc9a6('0x1e')},'attributes':[_0xc9a6('0x1f'),_0xc9a6('0x20')],'raw':!![]})['then'](function(_0x21539f){ADMIN=_0x21539f;_0x21ccf3+='|reason|'+_0x2484c2+'|\x0a';_0x21ccf3+=_0xc9a6('0x21')+_0x491195+'|\x0a';_0x21ccf3+=_0xc9a6('0x22')+_0x492f5c+'|\x0a';_0x21ccf3+=_0xc9a6('0x23')+ADMIN[_0xc9a6('0x1f')]+'|\x0a';_0x21ccf3+=_0xc9a6('0x24')+ADMIN['email']+'|\x0a';return _0x21ccf3;})[_0xc9a6('0x25')](function(_0x1f1796){var _0x9dbc05=hardware[_0xc9a6('0x26')]()['ipAddress'];return jira[_0xc9a6('0x27')]({'key':'MOTLICENSE','summary':_0xc9a6('0x28'),'description':_0x1f1796,'issuetype':_0xc9a6('0x29'),'oldToken':_0x491195,'newToken':_0x492f5c,'email':ADMIN[_0xc9a6('0x20')],'name':ADMIN[_0xc9a6('0x1f')],'reason':GRAY_PERIOD_REASON,'ip':_0x9dbc05});});}function manageLicense(_0x22568d,_0xf6abe1){var _0x9bb7e0=_0xf6abe1[_0xc9a6('0x2a')]({'plain':!![]});httpRequest(_0x22568d)['then'](function(_0x19fe5c){if(_0x19fe5c[_0xc9a6('0x2b')]){if(!_0x9bb7e0[_0xc9a6('0x8')]&&_0x9bb7e0[_0xc9a6('0x8')]!=_0x19fe5c[_0xc9a6('0x8')]||_0x9bb7e0[_0xc9a6('0x8')]&&_0x9bb7e0[_0xc9a6('0x2c')]){logger['info'](_0xc9a6('0x2d'));}if(_0x9bb7e0['license']&&!_0x9bb7e0[_0xc9a6('0x2c')]&&_0x9bb7e0[_0xc9a6('0x8')]!=_0x19fe5c[_0xc9a6('0x8')]){logger[_0xc9a6('0x2e')](_0xc9a6('0x2f'));}if(_0x9bb7e0['license']&&!_0x9bb7e0[_0xc9a6('0x2c')]&&_0x9bb7e0['license']==_0x19fe5c[_0xc9a6('0x8')]){return _0xf6abe1;}return _0xf6abe1[_0xc9a6('0x17')]({'data1':_0x22568d,'data2':null,'license':_0x19fe5c[_0xc9a6('0x8')]});}else{if(_0x19fe5c[_0xc9a6('0x8')]||_0x9bb7e0[_0xc9a6('0x8')]){if(!_0x9bb7e0[_0xc9a6('0x2c')]){if(_0x9bb7e0[_0xc9a6('0x30')]==_0x22568d){GRAY_PERIOD_REASON=_0xc9a6('0x31');logger['info'](_0xc9a6('0x32'));}else{GRAY_PERIOD_REASON=_0xc9a6('0x33');logger['info'](_0xc9a6('0x34'),_0x9bb7e0[_0xc9a6('0x30')],_0x22568d);}sendJiraAlert(_0x9bb7e0['data1'],_0x19fe5c[_0xc9a6('0x35')],GRAY_PERIOD_REASON);logger[_0xc9a6('0x2e')](_0xc9a6('0x36'),GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0xc9a6('0xb')]('YYYY-MM-DD\x20HH:mm'));return _0xf6abe1[_0xc9a6('0x17')]({'data2':encryptDate(moment()[_0xc9a6('0xb')](_0xc9a6('0x37')))});}else{if(moment()['diff'](decryptDate(_0x9bb7e0[_0xc9a6('0x2c')]),'days')>DAYS){logger['info']('DEMO\x20START\x20AT\x20%s',moment()[_0xc9a6('0xb')]('YYYY-MM-DD\x20HH:mm'));return _0xf6abe1[_0xc9a6('0x17')]({'data1':_0x22568d,'data2':null,'license':null});}}}else{if(_0x9bb7e0[_0xc9a6('0x30')]!=_0x22568d){logger[_0xc9a6('0x2e')](_0xc9a6('0x34'),_0x9bb7e0['data1'],_0x22568d);return _0xf6abe1[_0xc9a6('0x17')]({'data1':_0x22568d,'data2':null,'license':null});}}}return _0xf6abe1;})['then'](function(_0x56a737){_0xf6abe1=_0x56a737;})['catch'](function(_0x57b504){logger[_0xc9a6('0x38')](_0x57b504[_0xc9a6('0x39')]);})[_0xc9a6('0x3a')](function(){setTimeout(function(){manageLicense(hardware[_0xc9a6('0x3b')](),_0xf6abe1);},TIME);});}function defaultLicense(){var _0x5c9561=hardware[_0xc9a6('0x3b')]();if(_0x5c9561){return db[_0xc9a6('0x3c')][_0xc9a6('0x3d')]({'where':{'id':0x1},'defaults':{'data1':_0x5c9561}})[_0xc9a6('0x3e')](function(_0x532151,_0x1b74b2){logger[_0xc9a6('0x2e')](_0xc9a6('0x3f'),_0x5c9561);manageLicense(_0x5c9561,_0x532151);})[_0xc9a6('0x40')](function(_0x2a69ec){logger[_0xc9a6('0x38')](_0x2a69ec['message']);});}}exports['default']=defaultLicense;