GWM
This commit is contained in:
parent
97f7a88b0b
commit
389b5e57d6
@ -3,62 +3,76 @@ const {logMsg} = require('../services/logger')
|
||||
const secretKeyJwt = process.env.SECRETKEY;
|
||||
const { info, log } = require('winston');
|
||||
const moment = require('moment');
|
||||
|
||||
const Cryptr = require('cryptr');
|
||||
|
||||
|
||||
module.exports.addMacValue= async(req, res, next)=>{
|
||||
try {
|
||||
const today = moment().format('YYYY/MM/DD');
|
||||
const one_year = moment().add(1, 'year');
|
||||
const nextFiscalYearEndDate = one_year.format('YYYY/MM/DD');
|
||||
|
||||
const {key, mac_id, mail, company_name, app_version} = req.body
|
||||
|
||||
const cryptr = new Cryptr('7B-q;Vn@oGc^aPtk:0QP/SyDoHw!,(L2{2uZP&jZw5l]*>s~,%Z+kaD1tloQU', { encoding: 'base64', pbkdf2Iterations: 10000, saltLength: 5 });
|
||||
let {key, mac_id, company_name, app_version} = req.body
|
||||
|
||||
key = cryptr.decrypt(key);
|
||||
mac_id = cryptr.decrypt(mac_id);
|
||||
company_name = cryptr.decrypt(company_name);
|
||||
app_version = cryptr.decrypt(app_version);
|
||||
|
||||
const mac = await MacModel.findOne({where:{licency_key: key},raw:true});
|
||||
|
||||
console.log(mac);
|
||||
//Check License Key IN DB
|
||||
if (mac && mac.licency_key == key)
|
||||
{
|
||||
//Check isActive and App Version are Same
|
||||
if (mac.isActive == false && mac.app_version == app_version) {
|
||||
if (mac.isActive == false && mac.app_version.charAt(0) == app_version.charAt(0)) {
|
||||
|
||||
today = moment().format('YYYY/MM/DD');
|
||||
if(mac.expiry_type == 'Trail'){
|
||||
after10days = moment().add(10, 'day');
|
||||
formatedDate = after10days.format('YYYY/MM/DD');
|
||||
}else if(mac.expiry_type == 'One Year'){
|
||||
after1year = moment().add(1, 'year');
|
||||
formatedDate = after1year.format('YYYY/MM/DD');
|
||||
}else if(mac.expiry_type == 'Perpetual'){
|
||||
after20year = moment().add(20, 'year');
|
||||
formatedDate = after20year.format('YYYY/MM/DD');
|
||||
}
|
||||
|
||||
const info={
|
||||
licency_key:key,
|
||||
mac_id: mac_id,
|
||||
mail: mail,
|
||||
company_name: company_name,
|
||||
isActive:true,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
app_version : app_version
|
||||
activation_date: today,
|
||||
expiry_date : formatedDate,
|
||||
isActive : true,
|
||||
}
|
||||
|
||||
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
|
||||
console.log("Update ");
|
||||
console.log(macUpdate);
|
||||
|
||||
|
||||
if (macUpdate) {
|
||||
logMsg.info({status:200,message:"Your license has been successfully activated. ", data: info});
|
||||
res.send({status:200,message:"Your license has been successfully activated. ", data: info})
|
||||
logMsg.info({status:200,message:"Your license has been successfully activated. ", data: { expiry_date : cryptr.encrypt(formatedDate), expiry_type : cryptr.encrypt(mac.expiry_type) }});
|
||||
res.send({status:200,message:"Your license has been successfully activated. ", data: { expiry_date : cryptr.encrypt(formatedDate), expiry_type : cryptr.encrypt(mac.expiry_type) }})
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (mac.isActive == true && mac.app_version == app_version && mac_id == mac.mac_id)
|
||||
if (mac.isActive == true && mac.app_version.charAt(0) == app_version.charAt(0) && mac_id == mac.mac_id && mac.expiry_type != 'Trail' )
|
||||
{
|
||||
today = moment().format('YYYY/MM/DD');
|
||||
formatedDate = mac.expiry_date;
|
||||
|
||||
const info={
|
||||
licency_key:key,
|
||||
mac_id: mac_id,
|
||||
mail: mail,
|
||||
company_name: company_name,
|
||||
isActive:true,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
activation_date: today,
|
||||
expiry_date : formatedDate,
|
||||
isActive : true,
|
||||
}
|
||||
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
|
||||
console.log("Update ");
|
||||
console.log(macUpdate);
|
||||
|
||||
if (macUpdate) {
|
||||
logMsg.info({status:200,message:"Your license has been successfully activated.", data: info});
|
||||
res.send({status:200,message:" Your license has been successfully activated.", data: info})
|
||||
logMsg.info({status:200,message:"Your license has been successfully activated.", data: { expiry_date : cryptr.encrypt(formatedDate), expiry_type : cryptr.encrypt(mac.expiry_type) }});
|
||||
res.send({status:200,message:" Your license has been successfully activated.", data: { expiry_date : cryptr.encrypt(formatedDate), expiry_type : cryptr.encrypt(mac.expiry_type) }})
|
||||
}
|
||||
|
||||
}else{
|
||||
@ -68,17 +82,56 @@ module.exports.addMacValue= async(req, res, next)=>{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
logMsg.info({status:404,message:"The license key you provided is not valid. Please check the license key and try again. For further assistance, contact our support team.", data: "No Data"});
|
||||
res.send({status:404,message:"The license key you provided is not valid. Please check the license key and try again. For further assistance, contact our support team.", data: "No Data"})
|
||||
}
|
||||
} catch (error) {
|
||||
logMsg.info("addMacValue ->Internal Server Error!", error);
|
||||
console.error(error);
|
||||
res.status(404).send('addMacValue ->Internal Server Error!', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports.encryptLicenseKey= async(req, res, next)=>{
|
||||
|
||||
|
||||
|
||||
const cryptr = new Cryptr('myTotallySecretKey', { saltLength: 5 });
|
||||
|
||||
//const encryptedString = cryptr.encrypt('Gowtham');
|
||||
const decryptedString = cryptr.decrypt('cf1496215367f9713a67c81c6c22c5409f46ea5b0be610cf60f5b8717aac8ac1691c05e6d68b2178a9e4ce1f');
|
||||
res.send({decryptedString:decryptedString});
|
||||
|
||||
};
|
||||
|
||||
module.exports.decryptLicenseKey= async(req, res, next)=>{
|
||||
|
||||
const algorithm = 'aes-256-cbc';
|
||||
const key = crypto.randomBytes(32);
|
||||
const iv = crypto.randomBytes(16);
|
||||
|
||||
const decipher = crypto.createDecipheriv(algorithm, '51 70 c0 16 42 ef 9a 13 2e e6 9d d0 b0 02 cf 1e c2 31 dd 04 7e 77 cc 5d aa ea 72 5a cb c8 4a b9', '7e 4e c7 f6 a3 27 ac 0f 4f c9 d8 19 0a 36 de f0');
|
||||
|
||||
let decrypted = decipher.update(req.query.encrypted_value, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
res.send({decrypted:decrypted});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// var expiryDate = new Date(mac.expiry_date);
|
||||
|
||||
// //Check expired or not!
|
||||
// if (expiryDate > new Date()) {
|
||||
// const info={
|
||||
// licency_key: key,
|
||||
// mail: mail,
|
||||
|
||||
// company_name: company_name,
|
||||
// activation_date:today,
|
||||
// expiry_date:nextFiscalYearEndDate,
|
||||
@ -127,15 +180,4 @@ module.exports.addMacValue= async(req, res, next)=>{
|
||||
// } else {
|
||||
// logMsg.info({status:404,message:" Your Mac is Not Match!", data: "No Data!"});
|
||||
// res.send({status:404,message:" Your Mac is Not Match!", data: "No Data!"});
|
||||
// }
|
||||
}
|
||||
}else{
|
||||
logMsg.info({status:404,message:"The license key you provided is not valid. Please check the license key and try again. For further assistance, contact our support team.", data: "No Data"});
|
||||
res.send({status:404,message:"The license key you provided is not valid. Please check the license key and try again. For further assistance, contact our support team.", data: "No Data"})
|
||||
}
|
||||
} catch (error) {
|
||||
logMsg.info("addMacValue ->Internal Server Error!", error);
|
||||
console.error(error);
|
||||
res.status(404).send('addMacValue ->Internal Server Error!', error);
|
||||
}
|
||||
}
|
||||
// }
|
||||
@ -9,7 +9,6 @@ module.exports = (sequelize, DataTypes) => {
|
||||
{
|
||||
licency_key: {type: DataTypes.STRING},
|
||||
mac_id:{type: DataTypes.TEXT },
|
||||
mail: {type: DataTypes.STRING},
|
||||
company_name: {type: DataTypes.STRING},
|
||||
activation_date: {type: DataTypes.STRING,},
|
||||
expiry_type: { type: DataTypes.STRING, defaultValue: 'One Year' },
|
||||
|
||||
@ -67,6 +67,9 @@ const Mycontroller = require('../controllers/jwt_controller');
|
||||
|
||||
router.post('/addMacValue', Mycontroller.addMacValue)
|
||||
|
||||
router.get('/encryptLicenseKey', Mycontroller.encryptLicenseKey)
|
||||
router.get('/decryptLicenseKey', Mycontroller.decryptLicenseKey)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@ -13,6 +13,7 @@
|
||||
"cookie": "^0.6.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
"cryptr": "^6.3.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"ejs": "^3.1.9",
|
||||
"email-domain-check": "^1.1.4",
|
||||
@ -1370,6 +1371,11 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/cryptr": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/cryptr/-/cryptr-6.3.0.tgz",
|
||||
"integrity": "sha512-TA4byAuorT8qooU9H8YJhBwnqD151i1rcauHfJ3Divg6HmukHB2AYMp0hmjv2873J2alr4t15QqC7zAnWFrtfQ=="
|
||||
},
|
||||
"node_modules/css-tree": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz",
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
"cookie": "^0.6.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
"cryptr": "^6.3.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"ejs": "^3.1.9",
|
||||
"email-domain-check": "^1.1.4",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user