Built motion from commit (unavailable).|2.5.24
[motion2.git] / server / config / license / index.js
index ca1503a..cc79830 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb411=['util','request-promise','bluebird','../../mysqldb','../../components/encryptor','./hardware','../logger','../../api/jira/jira.controller','https://www.xcallymotion.com','version','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','exports','then','catch','||FIELD||VALUE||\x0a','User','findOne','admin','fullname','email','|reason|','|uuid|','|name|','|email|','getFirstInterface','ipAddress','openIssue','MOTLICENSE','Alert','active','license','data2','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','data1','Disabled','info','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','update','encryptString','diff','decryptString','DEMO\x20START\x20AT\x20%s','error','message','getUuid','License','SERVICE\x20LICENSE\x20STARTED\x20%s','default'];(function(_0x122938,_0x1223d0){var _0x1363cc=function(_0x683697){while(--_0x683697){_0x122938['push'](_0x122938['shift']());}};_0x1363cc(++_0x1223d0);}(_0xb411,0xa2));var _0x1b41=function(_0x177ffa,_0x291307){_0x177ffa=_0x177ffa-0x0;var _0x4aa82b=_0xb411[_0x177ffa];return _0x4aa82b;};'use strict';var util=require(_0x1b41('0x0'));var moment=require('moment');var rp=require(_0x1b41('0x1'));var BPromise=require(_0x1b41('0x2'));var pkginfo=require('pkginfo')(module,'version');var db=require(_0x1b41('0x3'))['db'];var encryptor=require(_0x1b41('0x4'));var hardware=require(_0x1b41('0x5'));var logger=require(_0x1b41('0x6'))('license');var jira=require(_0x1b41('0x7'));const {config}=require('process');var HOST=_0x1b41('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var ADMIN;var oldToken;function httpRequest(_0x20694b){return new BPromise(function(_0x53998f,_0x258fdb){var _0x1095e6=util['format']('%s/api/servers/%s/check?version=%s',HOST,_0x20694b,module['exports'][_0x1b41('0x9')]);if(oldToken){_0x1095e6=util[_0x1b41('0xa')](_0x1b41('0xb'),HOST,_0x20694b,module[_0x1b41('0xc')][_0x1b41('0x9')],oldToken);}var _0x3851e0={'uri':_0x1095e6,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x3851e0)[_0x1b41('0xd')](function(_0x51e797){_0x53998f(_0x51e797);})[_0x1b41('0xe')](function(_0x32c5c1){_0x258fdb(_0x32c5c1);});});}function sendJiraAlert(_0x560574,_0x16effe,_0x108dfc){var _0x29df03=_0x1b41('0xf');return db[_0x1b41('0x10')][_0x1b41('0x11')]({'where':{'role':_0x1b41('0x12')},'attributes':[_0x1b41('0x13'),_0x1b41('0x14')],'raw':!![]})[_0x1b41('0xd')](function(_0x5c15fa){ADMIN=_0x5c15fa;_0x29df03+=_0x1b41('0x15')+_0x108dfc+'|\x0a';_0x29df03+=_0x1b41('0x16')+_0x560574+'|\x0a';_0x29df03+='|machineUuid|'+_0x16effe+'|\x0a';_0x29df03+=_0x1b41('0x17')+ADMIN[_0x1b41('0x13')]+'|\x0a';_0x29df03+=_0x1b41('0x18')+ADMIN['email']+'|\x0a';return _0x29df03;})[_0x1b41('0xd')](function(_0x40e758){var _0x5a8929=hardware[_0x1b41('0x19')]()[_0x1b41('0x1a')];return jira[_0x1b41('0x1b')]({'key':_0x1b41('0x1c'),'summary':'Motion\x20License\x20Alert','description':_0x40e758,'issuetype':_0x1b41('0x1d'),'oldToken':_0x560574,'newToken':_0x16effe,'email':ADMIN[_0x1b41('0x14')],'name':ADMIN[_0x1b41('0x13')],'reason':GRAY_PERIOD_REASON,'ip':_0x5a8929});});}function manageLicense(_0x3435c4,_0x5860c6){var _0x7940e5=_0x5860c6['get']({'plain':!![]});httpRequest(_0x3435c4)[_0x1b41('0xd')](function(_0x4e9fa2){if(oldToken){oldToken=undefined;}if(_0x4e9fa2[_0x1b41('0x1e')]){if(!_0x7940e5[_0x1b41('0x1f')]&&_0x7940e5[_0x1b41('0x1f')]!=_0x4e9fa2[_0x1b41('0x1f')]||_0x7940e5[_0x1b41('0x1f')]&&_0x7940e5[_0x1b41('0x20')]){logger['info'](_0x1b41('0x21'));}if(_0x7940e5[_0x1b41('0x1f')]&&!_0x7940e5[_0x1b41('0x20')]&&_0x7940e5[_0x1b41('0x1f')]!=_0x4e9fa2[_0x1b41('0x1f')]){logger['info'](_0x1b41('0x22'));}if(_0x7940e5[_0x1b41('0x1f')]&&!_0x7940e5[_0x1b41('0x20')]&&_0x7940e5[_0x1b41('0x1f')]==_0x4e9fa2[_0x1b41('0x1f')]){return _0x5860c6;}return _0x5860c6['update']({'data1':_0x3435c4,'data2':null,'license':_0x4e9fa2['license']});}else{if(_0x4e9fa2[_0x1b41('0x1f')]||_0x7940e5[_0x1b41('0x1f')]){if(!_0x7940e5[_0x1b41('0x20')]){if(_0x7940e5[_0x1b41('0x23')]==_0x3435c4){GRAY_PERIOD_REASON=_0x1b41('0x24');logger[_0x1b41('0x25')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x1b41('0x26');oldToken=_0x7940e5[_0x1b41('0x23')];logger[_0x1b41('0x25')](_0x1b41('0x27'),_0x7940e5[_0x1b41('0x23')],_0x3435c4);}sendJiraAlert(_0x7940e5[_0x1b41('0x23')],_0x4e9fa2['uuid'],GRAY_PERIOD_REASON);logger[_0x1b41('0x25')](_0x1b41('0x28'),GRAY_PERIOD_REASON[_0x1b41('0x29')](),moment()['format'](_0x1b41('0x2a')));return _0x5860c6[_0x1b41('0x2b')]({'data2':encryptor[_0x1b41('0x2c')](moment()[_0x1b41('0xa')]('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0x1b41('0x2d')](encryptor[_0x1b41('0x2e')](_0x7940e5['data2']),'days')>DAYS){logger[_0x1b41('0x25')](_0x1b41('0x2f'),moment()['format'](_0x1b41('0x2a')));return _0x5860c6[_0x1b41('0x2b')]({'data1':_0x3435c4,'data2':null,'license':null});}}}else{if(_0x7940e5[_0x1b41('0x23')]!=_0x3435c4){logger[_0x1b41('0x25')](_0x1b41('0x27'),_0x7940e5['data1'],_0x3435c4);return _0x5860c6[_0x1b41('0x2b')]({'data1':_0x3435c4,'data2':null,'license':null});}}}return _0x5860c6;})[_0x1b41('0xd')](function(_0x135302){_0x5860c6=_0x135302;})[_0x1b41('0xe')](function(_0x305aa4){logger[_0x1b41('0x30')](_0x305aa4[_0x1b41('0x31')]);})['finally'](function(){setTimeout(function(){manageLicense(hardware[_0x1b41('0x32')](),_0x5860c6);},TIME);});}function defaultLicense(){var _0x26892f=hardware[_0x1b41('0x32')]();if(_0x26892f){return db[_0x1b41('0x33')]['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x26892f}})['spread'](function(_0x5cc55d,_0x2b8068){logger[_0x1b41('0x25')](_0x1b41('0x34'),_0x26892f);manageLicense(_0x26892f,_0x5cc55d);})[_0x1b41('0xe')](function(_0x4b094c){logger[_0x1b41('0x30')](_0x4b094c[_0x1b41('0x31')]);});}}exports[_0x1b41('0x35')]=defaultLicense;
\ No newline at end of file
+var _0x9fea=['../../components/encryptor','./hardware','../logger','license','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','GET','catch','get','data2','data1','then','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','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','error','finally','getUuid','findOrCreate','spread','message','default','util','moment','request-promise','pkginfo','version','../../mysqldb'];(function(_0x8ee422,_0x5c815f){var _0x322f12=function(_0x5d7a04){while(--_0x5d7a04){_0x8ee422['push'](_0x8ee422['shift']());}};_0x322f12(++_0x5c815f);}(_0x9fea,0x75));var _0xa9fe=function(_0x5d2033,_0x8e34f8){_0x5d2033=_0x5d2033-0x0;var _0x340eda=_0x9fea[_0x5d2033];return _0x340eda;};'use strict';var util=require(_0xa9fe('0x0'));var moment=require(_0xa9fe('0x1'));var rp=require(_0xa9fe('0x2'));var BPromise=require('bluebird');var pkginfo=require(_0xa9fe('0x3'))(module,_0xa9fe('0x4'));var db=require(_0xa9fe('0x5'))['db'];var encryptor=require(_0xa9fe('0x6'));var hardware=require(_0xa9fe('0x7'));var logger=require(_0xa9fe('0x8'))(_0xa9fe('0x9'));var HOST=_0xa9fe('0xa');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x469849){return new BPromise(function(_0x14938a,_0x32c21d){var _0x499a0b=util[_0xa9fe('0xb')](_0xa9fe('0xc'),HOST,_0x469849,module[_0xa9fe('0xd')]['version']);if(oldToken){_0x499a0b=util[_0xa9fe('0xb')]('%s/api/servers/%s/check?version=%s&oldtoken=%s',HOST,_0x469849,module[_0xa9fe('0xd')][_0xa9fe('0x4')],oldToken);}var _0x58c7ac={'uri':_0x499a0b,'method':_0xa9fe('0xe'),'timeout':0xea60,'json':!![]};return rp(_0x58c7ac)['then'](function(_0x3f44d0){_0x14938a(_0x3f44d0);})[_0xa9fe('0xf')](function(_0xfb58c0){_0x32c21d(_0xfb58c0);});});}function manageLicense(_0x5e90a4,_0x11ba57){var _0x41f3a1=_0x11ba57[_0xa9fe('0x10')]({'plain':!![]});if(!isOldTokenSent&&_0x41f3a1['data1']!==_0x5e90a4&&!_0x41f3a1[_0xa9fe('0x11')]){oldToken=_0x41f3a1[_0xa9fe('0x12')];}httpRequest(_0x5e90a4)[_0xa9fe('0x13')](function(_0x4333c4){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x4333c4['active']){isOldTokenSent=![];if(!_0x41f3a1[_0xa9fe('0x9')]&&_0x41f3a1[_0xa9fe('0x9')]!=_0x4333c4['license']||_0x41f3a1[_0xa9fe('0x9')]&&_0x41f3a1[_0xa9fe('0x11')]){logger[_0xa9fe('0x14')](_0xa9fe('0x15'));}if(_0x41f3a1['license']&&!_0x41f3a1[_0xa9fe('0x11')]&&_0x41f3a1[_0xa9fe('0x9')]!=_0x4333c4['license']){logger['info'](_0xa9fe('0x16'));}if(_0x41f3a1['license']&&!_0x41f3a1[_0xa9fe('0x11')]&&_0x41f3a1[_0xa9fe('0x9')]==_0x4333c4['license']){return _0x11ba57;}return _0x11ba57[_0xa9fe('0x17')]({'data1':_0x5e90a4,'data2':null,'license':_0x4333c4[_0xa9fe('0x9')]});}else{if(_0x4333c4['license']||_0x41f3a1[_0xa9fe('0x9')]){if(!_0x41f3a1[_0xa9fe('0x11')]){if(_0x41f3a1[_0xa9fe('0x12')]==_0x5e90a4){GRAY_PERIOD_REASON=_0xa9fe('0x18');logger[_0xa9fe('0x14')](_0xa9fe('0x19'));}else{GRAY_PERIOD_REASON='Changed';logger['info'](_0xa9fe('0x1a'),_0x41f3a1[_0xa9fe('0x12')],_0x5e90a4);}logger[_0xa9fe('0x14')](_0xa9fe('0x1b'),GRAY_PERIOD_REASON[_0xa9fe('0x1c')](),moment()[_0xa9fe('0xb')](_0xa9fe('0x1d')));return _0x11ba57['update']({'data2':encryptor[_0xa9fe('0x1e')](moment()['format'](_0xa9fe('0x1d')))});}else{if(moment()['diff'](encryptor[_0xa9fe('0x1f')](_0x41f3a1[_0xa9fe('0x11')]),_0xa9fe('0x20'))>DAYS){logger[_0xa9fe('0x14')](_0xa9fe('0x21'),moment()[_0xa9fe('0xb')](_0xa9fe('0x1d')));isOldTokenSent=![];return _0x11ba57[_0xa9fe('0x17')]({'data1':_0x5e90a4,'data2':null,'license':null});}}}else{if(_0x41f3a1[_0xa9fe('0x12')]!=_0x5e90a4){logger['info'](_0xa9fe('0x1a'),_0x41f3a1[_0xa9fe('0x12')],_0x5e90a4);return _0x11ba57[_0xa9fe('0x17')]({'data1':_0x5e90a4,'data2':null,'license':null});}}}return _0x11ba57;})[_0xa9fe('0x13')](function(_0x48d6c7){_0x11ba57=_0x48d6c7;})[_0xa9fe('0xf')](function(_0x25ca46){logger[_0xa9fe('0x22')](_0x25ca46['message']);})[_0xa9fe('0x23')](function(){setTimeout(function(){manageLicense(hardware[_0xa9fe('0x24')](),_0x11ba57);},TIME);});}function defaultLicense(){var _0x482b1e=hardware[_0xa9fe('0x24')]();if(_0x482b1e){return db['License'][_0xa9fe('0x25')]({'where':{'id':0x1},'defaults':{'data1':_0x482b1e}})[_0xa9fe('0x26')](function(_0x435d5e,_0x13c1af){logger[_0xa9fe('0x14')]('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x482b1e);manageLicense(_0x482b1e,_0x435d5e);})[_0xa9fe('0xf')](function(_0x40bfb5){logger[_0xa9fe('0x22')](_0x40bfb5[_0xa9fe('0x27')]);});}}exports[_0xa9fe('0x28')]=defaultLicense;
\ No newline at end of file