Built motion from commit (unavailable).|2.2.5
[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 _0xf723=['Motion\x20License\x20Alert','get','active','data2','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','data1','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','days','DEMO\x20START\x20AT\x20%s','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default','moment','bluebird','pkginfo','version','../../mysqldb','../environment','./hardware','../logger','license','../../api/jira/jira.controller','format','/api/servers/%s/check?version=%s','exports','GET','request','utf8','parse','error','end','createCipher','aes-256-ctr','session','base64','final','secrets','||FIELD||VALUE||\x0a','findOne','admin','fullname','email','then','|reason|','|uuid|','|machineUuid|','|name|','|email|','getFirstInterface','openIssue','MOTLICENSE'];(function(_0x7cb10c,_0x2fcc3a){var _0x11df59=function(_0x75305f){while(--_0x75305f){_0x7cb10c['push'](_0x7cb10c['shift']());}};_0x11df59(++_0x2fcc3a);}(_0xf723,0xcd));var _0x3f72=function(_0x205c11,_0x941d3d){_0x205c11=_0x205c11-0x0;var _0x550e7b=_0xf723[_0x205c11];return _0x550e7b;};'use strict';var util=require('util');var https=require('https');var crypto=require('crypto');var moment=require(_0x3f72('0x0'));var BPromise=require(_0x3f72('0x1'));var pkginfo=require(_0x3f72('0x2'))(module,_0x3f72('0x3'));var db=require(_0x3f72('0x4'))['db'];var config=require(_0x3f72('0x5'));var hardware=require(_0x3f72('0x6'));var logger=require(_0x3f72('0x7'))(_0x3f72('0x8'));var jira=require(_0x3f72('0x9'));var HOST='www.xcallymotion.com';var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var ADMIN;function httpRequest(_0x238890){return new BPromise(function(_0x422d49,_0x4209f9){var _0x42cf88={'host':HOST,'port':0x1bb,'path':util[_0x3f72('0xa')](_0x3f72('0xb'),_0x238890,module[_0x3f72('0xc')][_0x3f72('0x3')]),'method':_0x3f72('0xd'),'timeout':0xea60,'headers':{'Content-Type':'application/json'}};var _0x55fb32=https[_0x3f72('0xe')](_0x42cf88,function(_0x507c96){_0x507c96['setEncoding'](_0x3f72('0xf'));var _0xabb3d3='';_0x507c96['on']('data',function(_0xabd0be){_0xabb3d3+=_0xabd0be;});_0x507c96['on']('end',function(){try{_0x422d49(JSON[_0x3f72('0x10')](_0xabb3d3));}catch(_0x33c414){_0x4209f9(_0x33c414);}});});_0x55fb32['on'](_0x3f72('0x11'),_0x4209f9);_0x55fb32[_0x3f72('0x12')]();});}function encryptDate(_0x31f591){var _0x5b7f4d=crypto[_0x3f72('0x13')](_0x3f72('0x14'),config['secrets'][_0x3f72('0x15')]);var _0x262914=_0x5b7f4d['update'](_0x31f591,_0x3f72('0xf'),_0x3f72('0x16'));_0x262914+=_0x5b7f4d[_0x3f72('0x17')]('base64');return _0x262914;}function decryptDate(_0x2dcd57){var _0x24fc9f=crypto['createDecipher'](_0x3f72('0x14'),config[_0x3f72('0x18')]['session']);var _0x52a009=_0x24fc9f['update'](_0x2dcd57,'base64',_0x3f72('0xf'));_0x52a009+=_0x24fc9f[_0x3f72('0x17')](_0x3f72('0xf'));return _0x52a009;}function sendJiraAlert(_0xe6d149,_0x39bcd8,_0xa877f){var _0x5ee2b7=_0x3f72('0x19');return db['User'][_0x3f72('0x1a')]({'where':{'role':_0x3f72('0x1b')},'attributes':[_0x3f72('0x1c'),_0x3f72('0x1d')],'raw':!![]})[_0x3f72('0x1e')](function(_0x4b21a6){ADMIN=_0x4b21a6;_0x5ee2b7+=_0x3f72('0x1f')+_0xa877f+'|\x0a';_0x5ee2b7+=_0x3f72('0x20')+_0xe6d149+'|\x0a';_0x5ee2b7+=_0x3f72('0x21')+_0x39bcd8+'|\x0a';_0x5ee2b7+=_0x3f72('0x22')+ADMIN[_0x3f72('0x1c')]+'|\x0a';_0x5ee2b7+=_0x3f72('0x23')+ADMIN[_0x3f72('0x1d')]+'|\x0a';return _0x5ee2b7;})[_0x3f72('0x1e')](function(_0x1c3c81){var _0x4abfe8=hardware[_0x3f72('0x24')]()['ipAddress'];return jira[_0x3f72('0x25')]({'key':_0x3f72('0x26'),'summary':_0x3f72('0x27'),'description':_0x1c3c81,'issuetype':'Alert','oldToken':_0xe6d149,'newToken':_0x39bcd8,'email':ADMIN['email'],'name':ADMIN['fullname'],'reason':GRAY_PERIOD_REASON,'ip':_0x4abfe8});});}function manageLicense(_0x541f32,_0x47d812){var _0x1d4c85=_0x47d812[_0x3f72('0x28')]({'plain':!![]});httpRequest(_0x541f32)[_0x3f72('0x1e')](function(_0x12d8d9){if(_0x12d8d9[_0x3f72('0x29')]){if(!_0x1d4c85[_0x3f72('0x8')]&&_0x1d4c85[_0x3f72('0x8')]!=_0x12d8d9[_0x3f72('0x8')]||_0x1d4c85[_0x3f72('0x8')]&&_0x1d4c85[_0x3f72('0x2a')]){logger[_0x3f72('0x2b')](_0x3f72('0x2c'));}if(_0x1d4c85[_0x3f72('0x8')]&&!_0x1d4c85[_0x3f72('0x2a')]&&_0x1d4c85[_0x3f72('0x8')]!=_0x12d8d9[_0x3f72('0x8')]){logger[_0x3f72('0x2b')](_0x3f72('0x2d'));}if(_0x1d4c85[_0x3f72('0x8')]&&!_0x1d4c85[_0x3f72('0x2a')]&&_0x1d4c85[_0x3f72('0x8')]==_0x12d8d9['license']){return _0x47d812;}return _0x47d812[_0x3f72('0x2e')]({'data1':_0x541f32,'data2':null,'license':_0x12d8d9['license']});}else{if(_0x12d8d9['license']||_0x1d4c85[_0x3f72('0x8')]){if(!_0x1d4c85['data2']){if(_0x1d4c85['data1']==_0x541f32){GRAY_PERIOD_REASON='Disabled';logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON='Changed';logger[_0x3f72('0x2b')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x1d4c85[_0x3f72('0x2f')],_0x541f32);}sendJiraAlert(_0x1d4c85[_0x3f72('0x2f')],_0x12d8d9['uuid'],GRAY_PERIOD_REASON);logger[_0x3f72('0x2b')](_0x3f72('0x30'),GRAY_PERIOD_REASON[_0x3f72('0x31')](),moment()[_0x3f72('0xa')](_0x3f72('0x32')));return _0x47d812[_0x3f72('0x2e')]({'data2':encryptDate(moment()[_0x3f72('0xa')](_0x3f72('0x32')))});}else{if(moment()['diff'](decryptDate(_0x1d4c85[_0x3f72('0x2a')]),_0x3f72('0x33'))>DAYS){logger[_0x3f72('0x2b')](_0x3f72('0x34'),moment()['format'](_0x3f72('0x32')));return _0x47d812['update']({'data1':_0x541f32,'data2':null,'license':null});}}}else{if(_0x1d4c85[_0x3f72('0x2f')]!=_0x541f32){logger[_0x3f72('0x2b')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x1d4c85[_0x3f72('0x2f')],_0x541f32);return _0x47d812[_0x3f72('0x2e')]({'data1':_0x541f32,'data2':null,'license':null});}}}return _0x47d812;})['then'](function(_0x2e32dd){_0x47d812=_0x2e32dd;})['catch'](function(_0x1c597e){logger[_0x3f72('0x11')](_0x1c597e[_0x3f72('0x35')]);})[_0x3f72('0x36')](function(){setTimeout(function(){manageLicense(hardware[_0x3f72('0x37')](),_0x47d812);},TIME);});}function defaultLicense(){var _0x24ca65=hardware['getUuid']();if(_0x24ca65){return db[_0x3f72('0x38')][_0x3f72('0x39')]({'where':{'id':0x1},'defaults':{'data1':_0x24ca65}})[_0x3f72('0x3a')](function(_0x2b1c8c,_0x3a5d15){logger[_0x3f72('0x2b')](_0x3f72('0x3b'),_0x24ca65);manageLicense(_0x24ca65,_0x2b1c8c);})['catch'](function(_0x55584b){logger[_0x3f72('0x11')](_0x55584b[_0x3f72('0x35')]);});}}exports[_0x3f72('0x3c')]=defaultLicense;