-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,82 @@ | ||
const indexjs = require("../../index.js"); | ||
const ejs = require("ejs"); | ||
const express = require("express"); | ||
const fetch = require("node-fetch"); | ||
const settings = require("../../settings.json"); | ||
const fetch = require('node-fetch'); | ||
|
||
|
||
module.exports.load = async function(app, db) { | ||
app.use('/assets', express.static('./assets')); | ||
app.all("/", async (req, res) => { | ||
if (req.session.pterodactyl) if (req.session.pterodactyl.id !== await db.get("users-" + req.session.userinfo.id)) return res.redirect("/login?prompt=none") | ||
if (req.session.pterodactyl && req.session.pterodactyl.id !== await db.get(`users-${req.session.userinfo.id}`)) | ||
return res.redirect("/login?prompt=none"); | ||
|
||
let theme = indexjs.get(req); | ||
if (theme.settings.mustbeloggedin.includes(req._parsedUrl.pathname)) if (!req.session.userinfo || !req.session.pterodactyl) return res.redirect("/login"); | ||
if (theme.settings.mustbeadmin.includes(req._parsedUrl.pathname)) { | ||
ejs.renderFile( | ||
`./themes/${theme.name}/${theme.settings.notfound}`, | ||
await eval(indexjs.renderdataeval), | ||
null, | ||
async function (err, str) { | ||
delete req.session.newaccount; | ||
if (!req.session.userinfo || !req.session.pterodactyl) { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occured on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.send("An error has occured while attempting to load this page. Please contact an administrator to fix this."); | ||
}; | ||
return res.send(str); | ||
}; | ||
if (theme.settings.mustbeloggedin.includes(req._parsedUrl.pathname) && (!req.session.userinfo || !req.session.pterodactyl)) | ||
return res.redirect("/login"); | ||
|
||
let cacheaccount = await fetch( | ||
settings.pterodactyl.domain + "/api/application/users/" + (await db.get("users-" + req.session.userinfo.id)) + "?include=servers", | ||
{ | ||
method: "get", | ||
headers: { 'Content-Type': 'application/json', "Authorization": `Bearer ${settings.pterodactyl.key}` } | ||
} | ||
); | ||
if (await cacheaccount.statusText == "Not Found") { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occured on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.send("An error has occured while attempting to load this page. Please contact an administrator to fix this."); | ||
}; | ||
return res.send(str); | ||
}; | ||
let cacheaccountinfo = JSON.parse(await cacheaccount.text()); | ||
|
||
req.session.pterodactyl = cacheaccountinfo.attributes; | ||
if (cacheaccountinfo.attributes.root_admin !== true) { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occured on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.send("An error has occured while attempting to load this page. Please contact an administrator to fix this."); | ||
}; | ||
return res.send(str); | ||
if (theme.settings.mustbeadmin.includes(req._parsedUrl.pathname)) { | ||
const renderPage = async (err, str) => { | ||
delete req.session.newaccount; | ||
if (!req.session.userinfo || !req.session.pterodactyl || err) { | ||
console.log(`[WEBSITE] An error has occurred on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.render("404.ejs", { err }); | ||
} | ||
let cacheAccount = await fetch( | ||
`${settings.pterodactyl.domain}/api/application/users/${(await db.get(`users-${req.session.userinfo.id}`))}?include=servers`, | ||
{ | ||
method: "GET", | ||
headers: { 'Content-Type': 'application/json', "Authorization": `Bearer ${settings.pterodactyl.key}` } | ||
} | ||
); | ||
if (await cacheAccount.statusText == "Not Found") { | ||
return res.send(str); | ||
} | ||
let cacheAccountInfo = JSON.parse(await cacheAccount.text()); | ||
req.session.pterodactyl = cacheAccountInfo.attributes; | ||
if (cacheAccountInfo.attributes.root_admin !== true) { | ||
return res.send(str); | ||
} | ||
ejs.renderFile( | ||
`./themes/${theme.name}/${theme.settings.index}`, | ||
await indexjs.renderdataeval(req), | ||
null, | ||
(err, str) => { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occurred on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.render("404.ejs", { err }); | ||
} | ||
delete req.session.newaccount; | ||
res.send(str); | ||
} | ||
); | ||
}; | ||
|
||
ejs.renderFile( | ||
`./themes/${theme.name}/${theme.settings.index}`, | ||
await eval(indexjs.renderdataeval), | ||
null, | ||
function (err, str) { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occured on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.send("An error has occured while attempting to load this page. Please contact an administrator to fix this."); | ||
}; | ||
delete req.session.newaccount; | ||
res.send(str); | ||
}); | ||
}); | ||
return; | ||
}; | ||
`./themes/${theme.name}/${theme.settings.notfound}`, | ||
await indexjs.renderdataeval(req), | ||
null, | ||
renderPage | ||
); | ||
return; | ||
} | ||
ejs.renderFile( | ||
`./themes/${theme.name}/${theme.settings.index}`, | ||
await eval(indexjs.renderdataeval), | ||
null, | ||
function (err, str) { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occured on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.send("An error has occured while attempting to load this page. Please contact an administrator to fix this."); | ||
}; | ||
delete req.session.newaccount; | ||
res.send(str); | ||
}); | ||
`./themes/${theme.name}/${theme.settings.index}`, | ||
await indexjs.renderdataeval(req), | ||
null, | ||
(err, str) => { | ||
if (err) { | ||
console.log(`[WEBSITE] An error has occurred on path ${req._parsedUrl.pathname}:`); | ||
console.log(err); | ||
return res.render("404.ejs", { err }); | ||
} | ||
delete req.session.newaccount; | ||
res.send(str); | ||
} | ||
); | ||
}); | ||
|
||
app.use('/assets', express.static('./assets')); | ||
app.use('/cdn', express.static('./cdn')); | ||
}; | ||
}; |