Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const restapi = express();
- restapi.use(bodyParser.urlencoded({ extended: true }));
- restapi.listen(config.dashboard.port, config.dashboard.serverIP, () => {
- console.log(`Started the server, listening on port ${config.dashboard.port}`);
- });
- function genToken(length) {
- let key = ""
- let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
- for (let i = 0; i < length; i++) {
- key += possible.charAt(Math.floor(Math.random() * possible.length))
- }
- return key
- }
- let inivs = ["blacklisted", "commands", "botCmds"];
- restapi.get("/settings/:guild/:token", async function(req, res){
- let verify = await bot.db.fetch(`verification_${req.params.guild}`);
- if(!verify){
- verify = {
- code: genToken(7)
- }
- bot.db.set(`verification_${req.params.guild}`, verify);
- res.sendFile(path.join(__dirname, 'dashboard/error.html'));
- return;
- }
- if(req.params.token !== verify.code) return res.sendFile(path.join(__dirname, 'dashboard/invalid.html'));
- let html='';
- html += "<style>";
- html += "body {";
- html += "background-color: #2C2F33;";
- html += "color: #ffffff;";
- html += "font-family: 'Open Sans', sans-serif;";
- html += "text-align: center;";
- html += "}";
- html += "input[type=submit] {"
- html += "width: 10%;"
- html += "background-color: #99aab5;"
- html += "color: white;"
- html += "padding: 14px 20px;"
- html += "margin: 8px 0;"
- html += "border: none;"
- html += "border-radius: 50px;"
- html += "cursor: pointer;"
- html += "}"
- html += "input[type=submit]:hover {"
- html += "background-color: #23272a;"
- html += "}"
- html += "</style>";
- html += "<body>";
- let g = req.params.guild;
- html += `<form action='/settings/update/${g}' method='post' name='form1'>`;
- let entry = await bot.db.fetch(`config_${req.params.guild}`);
- if(!entry){
- bot.db.set(`config_${req.params.guild}`, bot.standard);
- res.sendFile(path.join(__dirname, 'dashboard/error.html'));
- return;
- }
- Object.entries(entry).forEach(([key, value]) => {
- if(inivs.includes(key)) return;
- html += `${key} : <input type='text' name='${key}' value='${value}'>`;
- html += "<br>";
- });
- html += "<input type='submit' value='Submit'>";
- html += "</form>";
- html += "</body>";
- res.send(html);
- bot.db.set(`verification_${req.params.guild}`, genToken(7), {target: ".code"});
- });
- let toParse = ["cmdcooldown", "cooldown", "antispam"]
- restapi.post("/settings/update/:guild", function(req, res){
- bot.db.set(`verification_${req.params.guild}`, genToken(7), {target: ".code"});
- let write = {};
- Object.entries(req.body).forEach(([key, value]) => {
- if(toParse.includes(key)) parseInt(key);
- write[key] = value;
- });
- bot.db.set(`config_${req.params.guild}`, write);
- res.sendFile(path.join(__dirname, 'dashboard/success.html'));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement