const express = require('express');
const app=express();
const bodyParser = require('body-parser');
const nunjucks     = require('nunjucks');
const regExp = require('time-limited-regular-expressions')({ limit: 2 });
app.use(bodyParser.urlencoded({extended:false}));
app.use('/static', express.static('static'));
app.set('views', './views');

nunjucks.configure("views", {
    autoescape: true,
    express: app,
    views: "templates",
});

app.get("/",(req,res)=>{
	return res.render("index.html");
});
app.get("/license",(req,res)=>{
	return res.render("license.html");
});
const checkLicense = async (license) => {
    try {
        const match = await regExp.match(license, process.env.FLAG)
        return !!match;
    } catch (error) {
        return false;
    }
}
app.post("/license",async(req,res)=>{
	// Nothing better than simple License checkers
    try{
        var result=await checkLicense(req.body.license)
        return res.render("license.html",{msg:"Result is saved successfully"})
    }
    catch(e){
        return res.render("license.html",{msg:"Result is saved successfully"})
    }
});

app.listen(8000,"0.0.0.0");
console.log("Listening 8000 ..")
