Compare commits
10 Commits
1a445ca96b
...
6f861cb6b2
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f861cb6b2 | |||
|
|
a63ad08425 | ||
|
|
3037c0453a | ||
|
|
d9a7283300 | ||
|
|
ec8f48efda | ||
|
|
6b7bb7905b | ||
|
|
7530795b04 | ||
|
|
ba827f538a | ||
|
|
389b5e57d6 | ||
|
|
97f7a88b0b |
@ -3,61 +3,222 @@ const {logMsg} = require('../services/logger')
|
|||||||
const secretKeyJwt = process.env.SECRETKEY;
|
const secretKeyJwt = process.env.SECRETKEY;
|
||||||
const { info, log } = require('winston');
|
const { info, log } = require('winston');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const Cryptr = require('cryptr');
|
||||||
|
|
||||||
|
|
||||||
module.exports.addMacValue= async(req, res, next)=>{
|
module.exports.addMacValue= async(req, res, next)=>{
|
||||||
try {
|
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 mac =await MacModel.findOne({where:{licency_key: key},raw:true});
|
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 mac = await MacModel.findOne({where:{licency_key: key},raw:true});
|
||||||
|
|
||||||
|
console.log(mac);
|
||||||
//Check License Key IN DB
|
//Check License Key IN DB
|
||||||
if (mac && mac.licency_key == key)
|
if (mac && mac.licency_key == key)
|
||||||
{
|
{
|
||||||
//Check isActive and App Version are Same
|
//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 == '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');
|
||||||
|
}
|
||||||
|
|
||||||
const info={
|
const info={
|
||||||
licency_key:key,
|
mac_id: mac_id,
|
||||||
mac_id: JSON.stringify(mac_id),
|
|
||||||
mail: mail,
|
|
||||||
company_name: company_name,
|
company_name: company_name,
|
||||||
isActive:true,
|
activation_date: today,
|
||||||
activation_date:today,
|
expiry_date : formatedDate,
|
||||||
expiry_date:nextFiscalYearEndDate,
|
isActive : true,
|
||||||
|
app_name : app_name
|
||||||
}
|
}
|
||||||
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
|
|
||||||
console.log("Update ");
|
|
||||||
console.log(macUpdate);
|
|
||||||
if (macUpdate) {
|
|
||||||
logMsg.info({status:200,message:"Update Success!", data: info});
|
|
||||||
res.send({status:200,message:" Update Success!", data: info})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var expiryDate = new Date(mac.expiry_date);
|
|
||||||
|
|
||||||
//Check expired or not!
|
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
|
||||||
if (expiryDate > new Date()) {
|
|
||||||
const info={
|
|
||||||
licency_key: key,
|
if (macUpdate) {
|
||||||
mail: mail,
|
logMsg.info({status:200,message:"Your license has been successfully activated. ", data: { expiry_date : cryptr.encrypt(formatedDate), expiry_type : cryptr.encrypt(mac.expiry_type) }});
|
||||||
company_name: company_name,
|
res.send({status:200,message:"Your license has been successfully activated. ", data: { expiry_date : cryptr.encrypt(formatedDate), expiry_type : cryptr.encrypt(mac.expiry_type) }})
|
||||||
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!"});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} 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){
|
||||||
|
|
||||||
|
const info={
|
||||||
|
mac_id: mac_id,
|
||||||
|
company_name: company_name,
|
||||||
|
activation_date: today,
|
||||||
|
expiry_date : formatedDate,
|
||||||
|
isActive : true,
|
||||||
|
app_name : app_name
|
||||||
|
}
|
||||||
|
const macUpdate = await MacModel.update(info, {where:{id: mac.id}});
|
||||||
|
|
||||||
|
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:"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);
|
// const macId = JSON.parse(mac.mac_id);
|
||||||
// var DBData= [];
|
// var DBData= [];
|
||||||
@ -94,15 +255,4 @@ module.exports.addMacValue= async(req, res, next)=>{
|
|||||||
// } else {
|
// } else {
|
||||||
// logMsg.info({status:404,message:" Your Mac is Not Match!", data: "No Data!"});
|
// 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!"});
|
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -9,13 +9,13 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
{
|
{
|
||||||
licency_key: {type: DataTypes.STRING},
|
licency_key: {type: DataTypes.STRING},
|
||||||
mac_id:{type: DataTypes.TEXT },
|
mac_id:{type: DataTypes.TEXT },
|
||||||
mail: {type: DataTypes.STRING},
|
|
||||||
company_name: {type: DataTypes.STRING},
|
company_name: {type: DataTypes.STRING},
|
||||||
activation_date: {type: DataTypes.STRING,},
|
activation_date: {type: DataTypes.STRING,},
|
||||||
expiry_type: { type: DataTypes.STRING, defaultValue: 'One Year' },
|
expiry_type: { type: DataTypes.STRING, defaultValue: 'One Year' },
|
||||||
expiry_date: {type: DataTypes.STRING},
|
expiry_date: {type: DataTypes.STRING},
|
||||||
isActive: {type: DataTypes.BOOLEAN,allowNull: false,defaultValue: false, },
|
isActive: {type: DataTypes.BOOLEAN,allowNull: false,defaultValue: false, },
|
||||||
app_version: { type: DataTypes.STRING, },
|
app_version: { type: DataTypes.STRING, },
|
||||||
|
app_name: { type: DataTypes.STRING, },
|
||||||
createdAt: {type: DataTypes.DATE,allowNull: true},
|
createdAt: {type: DataTypes.DATE,allowNull: true},
|
||||||
updatedAt: {type: DataTypes.DATE,allowNull: true}
|
updatedAt: {type: DataTypes.DATE,allowNull: true}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -67,6 +67,11 @@ const Mycontroller = require('../controllers/jwt_controller');
|
|||||||
|
|
||||||
router.post('/addMacValue', Mycontroller.addMacValue)
|
router.post('/addMacValue', Mycontroller.addMacValue)
|
||||||
|
|
||||||
|
router.post('/createLicencyKey', Mycontroller.createLicencyKey)
|
||||||
|
|
||||||
|
router.get('/encryptLicenseKey', Mycontroller.encryptLicenseKey)
|
||||||
|
router.get('/decryptLicenseKey', Mycontroller.decryptLicenseKey)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
8
index.js
8
index.js
@ -10,6 +10,10 @@ const swaggerUI = require('swagger-ui-express');
|
|||||||
const SWAGGERENDPOINT = process.env.SWAGGERENDPOINT;
|
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('views', path.join(__dirname, 'app\\views'));
|
||||||
app.set('view engine', 'ejs');
|
app.set('view engine', 'ejs');
|
||||||
app.use(express.static(path.join(__dirname, 'storage/css')));
|
app.use(express.static(path.join(__dirname, 'storage/css')));
|
||||||
@ -35,7 +39,7 @@ const swaggerOptions = {
|
|||||||
'./app/routes/jwt_route.js',
|
'./app/routes/jwt_route.js',
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const swaggerSpec = swaggerJSDoc(swaggerOptions);
|
const swaggerSpec = swaggerJSDoc(swaggerOptions);
|
||||||
app.use(`/api-docs`, swaggerUI.serve, swaggerUI.setup(swaggerSpec));
|
app.use(`/api-docs`, swaggerUI.serve, swaggerUI.setup(swaggerSpec));
|
||||||
@ -44,7 +48,7 @@ app.use(`/api-docs`, swaggerUI.serve, swaggerUI.setup(swaggerSpec));
|
|||||||
|
|
||||||
|
|
||||||
const go_home = require('./app/routes/jwt_route.js');
|
const go_home = require('./app/routes/jwt_route.js');
|
||||||
app.use('/',go_home)
|
app.use('/',go_home)
|
||||||
|
|
||||||
const PORT_NUMBER = process.env.SERVER_PORT;
|
const PORT_NUMBER = process.env.SERVER_PORT;
|
||||||
app.listen({ port: PORT_NUMBER }, async () => {
|
app.listen({ port: PORT_NUMBER }, async () => {
|
||||||
|
|||||||
2599
package-lock.json
generated
2599
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@
|
|||||||
"cookie": "^0.6.0",
|
"cookie": "^0.6.0",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"cryptr": "^6.3.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"ejs": "^3.1.9",
|
"ejs": "^3.1.9",
|
||||||
"email-domain-check": "^1.1.4",
|
"email-domain-check": "^1.1.4",
|
||||||
@ -34,7 +35,6 @@
|
|||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"mysql2": "^3.6.5",
|
"mysql2": "^3.6.5",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"nodemon": "^3.0.1",
|
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"random-code-generate": "^1.0.5",
|
"random-code-generate": "^1.0.5",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
@ -47,5 +47,8 @@
|
|||||||
"winston": "^3.3.3",
|
"winston": "^3.3.3",
|
||||||
"winston-daily-rotate-file": "^4.5.5",
|
"winston-daily-rotate-file": "^4.5.5",
|
||||||
"zxcvbn": "^4.4.2"
|
"zxcvbn": "^4.4.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^3.1.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user