Compare commits

..

No commits in common. "6f861cb6b26120c50f45a1e0fa8269e8a1b16790" and "1a445ca96bbe57f8e7b85d9f94dbecc61e4eade2" have entirely different histories.

6 changed files with 2601 additions and 260 deletions

View File

@ -3,222 +3,61 @@ 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 cryptr = new Cryptr('7B-q;Vn@oGc^aPtk:0QP/SyDoHw!,(L2{2uZP&jZw5l]*>s~,%Z+kaD1tloQU', { encoding: 'base64', pbkdf2Iterations: 10000, saltLength: 5 });
app_name = null;
let {key, mac_id, company_name, app_version } = req.body
if(req.body.hasOwnProperty('app_name')){
app_name = req.body.app_name;
}else{
app_name = null;
}
key = cryptr.decrypt(key);
mac_id = cryptr.decrypt(mac_id);
company_name = cryptr.decrypt(company_name);
app_version = cryptr.decrypt(app_version);
const {key, mac_id, mail, company_name, app_version} = req.body
const mac = await MacModel.findOne({where:{licency_key: key},raw:true});
console.log(mac);
const mac =await MacModel.findOne({where:{licency_key: key},raw:true});
//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.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 == 'ONEYR'){
after1year = moment().add(1, 'year');
formatedDate = after1year.format('YYYY/MM/DD');
}else if(mac.expiry_type == 'LYFT'){
after20year = moment().add(20, 'year');
formatedDate = after20year.format('YYYY/MM/DD');
}
if (mac.isActive == false && mac.app_version == app_version) {
const info={
mac_id: mac_id,
licency_key:key,
mac_id: JSON.stringify(mac_id),
mail: mail,
company_name: company_name,
activation_date: today,
expiry_date : formatedDate,
isActive : true,
app_name : app_name
isActive:true,
activation_date:today,
expiry_date:nextFiscalYearEndDate,
}
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: { 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) }})
logMsg.info({status:200,message:"Update Success!", data: info});
res.send({status:200,message:" Update Success!", data: info})
}
} else {
if (mac.isActive == true && mac.app_version.charAt(0) == app_version.charAt(0) && mac_id == mac.mac_id )
{
today = moment().format('YYYY/MM/DD');
formatedDate = moment(mac.expiry_date).format('YYYY/MM/DD');
if(formatedDate > today){
var expiryDate = new Date(mac.expiry_date);
//Check expired or not!
if (expiryDate > new Date()) {
const info={
mac_id: mac_id,
licency_key: key,
mail: mail,
company_name: company_name,
activation_date: today,
expiry_date : formatedDate,
isActive : true,
app_name : app_name
activation_date:today,
expiry_date:nextFiscalYearEndDate,
}
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
logMsg.info({status:404,message:" Your Mac is Already Activated!", data: info});
res.send({status:404,message:" Your Mac is Already Activated!", data: info});
if (macUpdate) {
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 {
logMsg.info({status:404,message:" Product Expired!", data: "No Data!"});
res.send({status:404,message:" Product Expired!", data: "No Data!"});
}
}else{
logMsg.info({status:404,message:"Please check the license key and try again. For further assistance, contact our support team.", data: "No Data"});
res.send({status:404,message:"Please check the license key and try again. For further assistance, contact our support team.", 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"})
}
}
}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.createLicencyKey = async (req, res, next) => {
try {
const { licency_key } = req.body;
// Check if license key already exists and is active
const mac = await MacModel.findOne({
where: { licency_key },
raw: true,
});
if (mac) {
logMsg.info({
status: 409,
message: "licency_key already exists and is active.",
data: null,
});
return res.status(409).send({
status: 409,
message: "licency_key already exists and is active.",
data: null,
});
}
// Create new license entry
const info = {
licency_key: licency_key,
expiry_type: 'TRAIL',
app_version: '1.0.0',
isActive: false,
};
const created = await MacModel.create(info);
logMsg.info({
status: 201,
message: "licency_key created.",
data: created,
});
return res.status(201).send({
status: 201,
message: "licency_key created.",
data: created,
});
} catch (error) {
console.error(error);
logMsg.error({ message: 'Licency key creation failed', error: error.message });
return res.status(500).send({
status: 500,
message: 'Licency key creation failed!',
error: error.message,
});
}
};
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,
// company_name: company_name,
// activation_date:today,
// expiry_date:nextFiscalYearEndDate,
// }
// logMsg.info({status:404,message:" Your Mac is Already Activated!", data: info});
// res.send({status:404,message:" Your Mac is Already Activated!", data: info});
// } else {
// logMsg.info({status:404,message:" Product Expired!", data: "No Data!"});
// res.send({status:404,message:" Product Expired!", data: "No Data!"});
// }
// const macId = JSON.parse(mac.mac_id);
// var DBData= [];
@ -256,3 +95,14 @@ module.exports.decryptLicenseKey= async(req, res, next)=>{
// 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:" Licency Key is No Match DB!", data: "No Data"});
res.send({status:404,message:" Licency Key is No Match DB!", data: "No Data"})
}
} catch (error) {
logMsg.info("addMacValue ->Internal Server Error!", error);
console.error(error);
res.status(404).send('addMacValue ->Internal Server Error!', error);
}
}

View File

@ -9,13 +9,13 @@ 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' },
expiry_date: {type: DataTypes.STRING},
isActive: {type: DataTypes.BOOLEAN,allowNull: false,defaultValue: false, },
app_version: { type: DataTypes.STRING, },
app_name: { type: DataTypes.STRING, },
createdAt: {type: DataTypes.DATE,allowNull: true},
updatedAt: {type: DataTypes.DATE,allowNull: true}
},

View File

@ -67,11 +67,6 @@ const Mycontroller = require('../controllers/jwt_controller');
router.post('/addMacValue', Mycontroller.addMacValue)
router.post('/createLicencyKey', Mycontroller.createLicencyKey)
router.get('/encryptLicenseKey', Mycontroller.encryptLicenseKey)
router.get('/decryptLicenseKey', Mycontroller.decryptLicenseKey)

View File

@ -10,10 +10,6 @@ const swaggerUI = require('swagger-ui-express');
const SWAGGERENDPOINT = process.env.SWAGGERENDPOINT;
// Enable CORS for all routes
const cors = require('cors');
app.use(cors());
app.set('views', path.join(__dirname, 'app\\views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'storage/css')));

2599
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,6 @@
"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",
@ -35,6 +34,7 @@
"multer": "^1.4.5-lts.1",
"mysql2": "^3.6.5",
"node-forge": "^1.3.1",
"nodemon": "^3.0.1",
"path": "^0.12.7",
"random-code-generate": "^1.0.5",
"request": "^2.88.2",
@ -47,8 +47,5 @@
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5",
"zxcvbn": "^4.4.2"
},
"devDependencies": {
"nodemon": "^3.1.10"
}
}