Built motion from commit (unavailable).|2.5.14
[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 _0xfc74=['license','data2','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','data1','Changed','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','update','encryptString','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','catch','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','error','default','util','moment','request-promise','bluebird','pkginfo','../../mysqldb','../../components/encryptor','./hardware','../logger','../../api/jira/jira.controller','version','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','exports','GET','findOne','admin','fullname','then','|reason|','|machineUuid|','|name|','email','ipAddress','openIssue','Motion\x20License\x20Alert','Alert','active'];(function(_0x5e498f,_0x22de74){var _0x19574a=function(_0x91364e){while(--_0x91364e){_0x5e498f['push'](_0x5e498f['shift']());}};_0x19574a(++_0x22de74);}(_0xfc74,0x1d3));var _0x4fc7=function(_0xbc845b,_0x5b784a){_0xbc845b=_0xbc845b-0x0;var _0x5b0aca=_0xfc74[_0xbc845b];return _0x5b0aca;};'use strict';var util=require(_0x4fc7('0x0'));var moment=require(_0x4fc7('0x1'));var rp=require(_0x4fc7('0x2'));var BPromise=require(_0x4fc7('0x3'));var pkginfo=require(_0x4fc7('0x4'))(module,'version');var db=require(_0x4fc7('0x5'))['db'];var encryptor=require(_0x4fc7('0x6'));var hardware=require(_0x4fc7('0x7'));var logger=require(_0x4fc7('0x8'))('license');var jira=require(_0x4fc7('0x9'));const {config}=require('process');var HOST='https://www.xcallymotion.com';var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var ADMIN;var oldToken;function httpRequest(_0x2f7252){return new BPromise(function(_0x2e0ed5,_0x3b2c2d){var _0x38477b=util['format']('%s/api/servers/%s/check?version=%s',HOST,_0x2f7252,module['exports'][_0x4fc7('0xa')]);if(oldToken){_0x38477b=util[_0x4fc7('0xb')](_0x4fc7('0xc'),HOST,_0x2f7252,module[_0x4fc7('0xd')]['version'],oldToken);}var _0x4084db={'uri':_0x38477b,'method':_0x4fc7('0xe'),'timeout':0xea60,'json':!![]};return rp(_0x4084db)['then'](function(_0x3856fc){_0x2e0ed5(_0x3856fc);})['catch'](function(_0x2d1318){_0x3b2c2d(_0x2d1318);});});}function sendJiraAlert(_0x25bbd2,_0x5a9a39,_0x47650b){var _0x327326='||FIELD||VALUE||\x0a';return db['User'][_0x4fc7('0xf')]({'where':{'role':_0x4fc7('0x10')},'attributes':[_0x4fc7('0x11'),'email'],'raw':!![]})[_0x4fc7('0x12')](function(_0x32582b){ADMIN=_0x32582b;_0x327326+=_0x4fc7('0x13')+_0x47650b+'|\x0a';_0x327326+='|uuid|'+_0x25bbd2+'|\x0a';_0x327326+=_0x4fc7('0x14')+_0x5a9a39+'|\x0a';_0x327326+=_0x4fc7('0x15')+ADMIN[_0x4fc7('0x11')]+'|\x0a';_0x327326+='|email|'+ADMIN[_0x4fc7('0x16')]+'|\x0a';return _0x327326;})[_0x4fc7('0x12')](function(_0x4a6ca0){var _0x3abca2=hardware['getFirstInterface']()[_0x4fc7('0x17')];return jira[_0x4fc7('0x18')]({'key':'MOTLICENSE','summary':_0x4fc7('0x19'),'description':_0x4a6ca0,'issuetype':_0x4fc7('0x1a'),'oldToken':_0x25bbd2,'newToken':_0x5a9a39,'email':ADMIN[_0x4fc7('0x16')],'name':ADMIN[_0x4fc7('0x11')],'reason':GRAY_PERIOD_REASON,'ip':_0x3abca2});});}function manageLicense(_0x32b2d0,_0x45421a){var _0x1e8225=_0x45421a['get']({'plain':!![]});httpRequest(_0x32b2d0)[_0x4fc7('0x12')](function(_0x24af0d){if(oldToken){oldToken=undefined;}if(_0x24af0d[_0x4fc7('0x1b')]){if(!_0x1e8225[_0x4fc7('0x1c')]&&_0x1e8225['license']!=_0x24af0d[_0x4fc7('0x1c')]||_0x1e8225[_0x4fc7('0x1c')]&&_0x1e8225[_0x4fc7('0x1d')]){logger[_0x4fc7('0x1e')](_0x4fc7('0x1f'));}if(_0x1e8225['license']&&!_0x1e8225[_0x4fc7('0x1d')]&&_0x1e8225[_0x4fc7('0x1c')]!=_0x24af0d['license']){logger[_0x4fc7('0x1e')](_0x4fc7('0x20'));}if(_0x1e8225[_0x4fc7('0x1c')]&&!_0x1e8225[_0x4fc7('0x1d')]&&_0x1e8225['license']==_0x24af0d[_0x4fc7('0x1c')]){return _0x45421a;}return _0x45421a['update']({'data1':_0x32b2d0,'data2':null,'license':_0x24af0d[_0x4fc7('0x1c')]});}else{if(_0x24af0d[_0x4fc7('0x1c')]||_0x1e8225[_0x4fc7('0x1c')]){if(!_0x1e8225[_0x4fc7('0x1d')]){if(_0x1e8225[_0x4fc7('0x21')]==_0x32b2d0){GRAY_PERIOD_REASON='Disabled';logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x4fc7('0x22');oldToken=_0x1e8225['data1'];logger[_0x4fc7('0x1e')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x1e8225[_0x4fc7('0x21')],_0x32b2d0);}sendJiraAlert(_0x1e8225[_0x4fc7('0x21')],_0x24af0d['uuid'],GRAY_PERIOD_REASON);logger['info'](_0x4fc7('0x23'),GRAY_PERIOD_REASON[_0x4fc7('0x24')](),moment()[_0x4fc7('0xb')](_0x4fc7('0x25')));return _0x45421a[_0x4fc7('0x26')]({'data2':encryptor[_0x4fc7('0x27')](moment()[_0x4fc7('0xb')](_0x4fc7('0x25')))});}else{if(moment()[_0x4fc7('0x28')](encryptor[_0x4fc7('0x29')](_0x1e8225[_0x4fc7('0x1d')]),_0x4fc7('0x2a'))>DAYS){logger[_0x4fc7('0x1e')](_0x4fc7('0x2b'),moment()[_0x4fc7('0xb')](_0x4fc7('0x25')));return _0x45421a['update']({'data1':_0x32b2d0,'data2':null,'license':null});}}}else{if(_0x1e8225[_0x4fc7('0x21')]!=_0x32b2d0){logger[_0x4fc7('0x1e')](_0x4fc7('0x2c'),_0x1e8225[_0x4fc7('0x21')],_0x32b2d0);return _0x45421a[_0x4fc7('0x26')]({'data1':_0x32b2d0,'data2':null,'license':null});}}}return _0x45421a;})[_0x4fc7('0x12')](function(_0x5844d5){_0x45421a=_0x5844d5;})[_0x4fc7('0x2d')](function(_0x189d3c){logger['error'](_0x189d3c[_0x4fc7('0x2e')]);})[_0x4fc7('0x2f')](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x45421a);},TIME);});}function defaultLicense(){var _0x5bb1b1=hardware[_0x4fc7('0x30')]();if(_0x5bb1b1){return db[_0x4fc7('0x31')][_0x4fc7('0x32')]({'where':{'id':0x1},'defaults':{'data1':_0x5bb1b1}})[_0x4fc7('0x33')](function(_0x3057ba,_0x1d8835){logger[_0x4fc7('0x1e')](_0x4fc7('0x34'),_0x5bb1b1);manageLicense(_0x5bb1b1,_0x3057ba);})[_0x4fc7('0x2d')](function(_0x1f321a){logger[_0x4fc7('0x35')](_0x1f321a[_0x4fc7('0x2e')]);});}}exports[_0x4fc7('0x36')]=defaultLicense;