Advertisement
DieselGaming67

Untitled

Apr 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const restapi = express();
  2.  
  3. restapi.use(bodyParser.urlencoded({ extended: true }));
  4. restapi.listen(config.dashboard.port, config.dashboard.serverIP, () => {
  5.     console.log(`Started the server, listening on port ${config.dashboard.port}`);
  6. });
  7.  
  8. function genToken(length) {
  9.     let key = ""
  10.     let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  11.  
  12.     for (let i = 0; i < length; i++) {
  13.         key += possible.charAt(Math.floor(Math.random() * possible.length))
  14.     }
  15.  
  16.     return key
  17. }
  18. let inivs = ["blacklisted", "commands", "botCmds"];
  19.  
  20. restapi.get("/settings/:guild/:token", async function(req, res){
  21.     let verify = await bot.db.fetch(`verification_${req.params.guild}`);
  22.     if(!verify){
  23.         verify = {
  24.             code: genToken(7)
  25.         }
  26.         bot.db.set(`verification_${req.params.guild}`, verify);
  27.         res.sendFile(path.join(__dirname, 'dashboard/error.html'));
  28.         return;
  29.     }
  30.     if(req.params.token !== verify.code) return res.sendFile(path.join(__dirname, 'dashboard/invalid.html'));
  31.     let html='';
  32.     html += "<style>";
  33.     html += "body {";
  34.     html += "background-color: #2C2F33;";
  35.     html += "color: #ffffff;";
  36.     html += "font-family: 'Open Sans', sans-serif;";
  37.     html += "text-align: center;";
  38.     html += "}";
  39.     html += "input[type=submit] {"
  40.     html += "width: 10%;"
  41.     html += "background-color: #99aab5;"
  42.     html += "color: white;"
  43.     html += "padding: 14px 20px;"
  44.     html += "margin: 8px 0;"
  45.     html += "border: none;"
  46.     html += "border-radius: 50px;"
  47.     html += "cursor: pointer;"
  48.     html += "}"
  49.     html += "input[type=submit]:hover {"
  50.     html += "background-color: #23272a;"
  51.     html += "}"
  52.     html += "</style>";
  53.     html += "<body>";
  54.     let g = req.params.guild;
  55.     html += `<form action='/settings/update/${g}' method='post' name='form1'>`;
  56.     let entry = await bot.db.fetch(`config_${req.params.guild}`);
  57.     if(!entry){
  58.         bot.db.set(`config_${req.params.guild}`, bot.standard);
  59.         res.sendFile(path.join(__dirname, 'dashboard/error.html'));
  60.         return;
  61.     }
  62.     Object.entries(entry).forEach(([key, value]) => {
  63.         if(inivs.includes(key)) return;
  64.         html += `${key} : <input type='text' name='${key}' value='${value}'>`;
  65.         html += "<br>";
  66.     });
  67.     html += "<input type='submit' value='Submit'>";
  68.     html += "</form>";
  69.     html += "</body>";
  70.     res.send(html);
  71.     bot.db.set(`verification_${req.params.guild}`, genToken(7), {target: ".code"});
  72. });
  73.  
  74. let toParse = ["cmdcooldown", "cooldown", "antispam"]
  75. restapi.post("/settings/update/:guild", function(req, res){
  76.     bot.db.set(`verification_${req.params.guild}`, genToken(7), {target: ".code"});
  77.     let write = {};
  78.     Object.entries(req.body).forEach(([key, value]) => {
  79.         if(toParse.includes(key)) parseInt(key);
  80.         write[key] = value;
  81.     });
  82.     bot.db.set(`config_${req.params.guild}`, write);
  83.     res.sendFile(path.join(__dirname, 'dashboard/success.html'));
  84. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement