From c00ef22ee0bbc70e73c9f6169b3843d8fdb5f552 Mon Sep 17 00:00:00 2001 From: Plain <66025383+PlainDevelopment@users.noreply.github.com> Date: Sat, 18 Mar 2023 00:35:36 +0000 Subject: [PATCH] Bug fixes + additions --- dbd-soft-ui.d.ts | 4 ++++ index.js | 2 ++ package.json | 2 +- pages/admin/control.js | 15 +++++---------- pages/get/admin.js | 20 ++++++++------------ pages/get/debug.js | 2 +- pages/get/settings.js | 2 +- pages/post/guildSettings.js | 6 +++--- pages/post/logs.js | 2 +- utils/functions/settingsPage.js | 4 ++-- utils/initPages.js | 15 ++++++++++++++- views/admin.ejs | 4 ++-- views/commands.ejs | 4 ++-- views/credits.ejs | 26 +------------------------- views/debug.ejs | 2 +- views/error.ejs | 8 ++++---- views/guilds.ejs | 2 +- views/index.ejs | 2 +- views/partials/footer.ejs | 21 +++++++++++++-------- views/partials/sidebar.ejs | 2 +- views/settings.ejs | 2 +- 21 files changed, 69 insertions(+), 78 deletions(-) diff --git a/dbd-soft-ui.d.ts b/dbd-soft-ui.d.ts index 91f25655..f3bb2f2c 100644 --- a/dbd-soft-ui.d.ts +++ b/dbd-soft-ui.d.ts @@ -32,6 +32,10 @@ declare module "dbd-soft-ui" { } supporteMail: string, locales: Record, + footer: { + replaceDefault: boolean, + text: string, + } admin: { pterodactyl: { enabled: boolean, diff --git a/index.js b/index.js index dc34d48b..e56cd4f0 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,8 @@ module.exports = (themeConfig = {}) => { 'utf8' ), init: async (app, config) => { + if(!config?.useTheme404) return console.log(`${consolePrefix}${'You need to set useTheme404 to true in your DBD config otherwise Soft-UI will not work correctly!\n\nDashboard has not fully initialised due to this. Pages will 404!'.red}`); + let outdated = false ; (async () => { let check = await npmUpdater.update() diff --git a/package.json b/package.json index 859aaadd..04034874 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dbd-soft-ui", - "version": "1.6.40-beta.1", + "version": "1.6.41-beta.1", "typings": "dbd-soft-ui.d.ts", "author": { "name": "iMidnight" diff --git a/pages/admin/control.js b/pages/admin/control.js index 8be6b67f..2acdb17e 100644 --- a/pages/admin/control.js +++ b/pages/admin/control.js @@ -1,15 +1,10 @@ -const Nodeactyl = require('nodeactyl') - const npmUpdater = require('../../utils/updater/npm') const fileUpdater = require('../../utils/updater/files') module.exports = { page: '/control', execute: async (req, res, app, config, themeConfig, info) => { - const pterodactyl = new Nodeactyl.NodeactylClient( - themeConfig.admin.pterodactyl.panelLink, - themeConfig.admin.pterodactyl.apiKey - ) + const { uuid, action } = req.query if (!uuid && action && req.query.type) { if (req.query.type === 'npm') await npmUpdater.update() @@ -19,10 +14,10 @@ module.exports = { if (!uuid || !action) return res.sendStatus(412) try { - if (action === 'start') await pterodactyl.startServer(uuid) - if (action === 'restart') await pterodactyl.restartServer(uuid) - if (action === 'stop') await pterodactyl.stopServer(uuid) - if (action === 'kill') await pterodactyl.killServer(uuid) + if (action === 'start') await themeConfig.nodeactyl.startServer(uuid) + if (action === 'restart') await themeConfig.nodeactyl.restartServer(uuid) + if (action === 'stop') await themeConfig.nodeactyl.stopServer(uuid) + if (action === 'kill') await themeConfig.nodeactyl.killServer(uuid) } catch (error) { console.error(error) return res.redirect('/admin?result=false') diff --git a/pages/get/admin.js b/pages/get/admin.js index da640d09..e2f27a3f 100644 --- a/pages/get/admin.js +++ b/pages/get/admin.js @@ -1,27 +1,23 @@ -const Nodeactyl = require('nodeactyl') const db = require('quick.db') module.exports = { page: '/admin', execute: async (req, res, app, config, themeConfig, info, database) => { - const pterodactyl = new Nodeactyl.NodeactylClient( - themeConfig.admin.pterodactyl.panelLink, - themeConfig.admin.pterodactyl.apiKey - ) if (!req.session.user) return res.redirect('/discord?r=/admin/') - if (!config.ownerIDs.includes(req.session.user.id)) + if (!config.ownerIDs?.includes(req.session.user.id)) return res.redirect('/') - if (!pterodactyl && themeConfig.admin.pterodactyl.enabled) + if (!themeConfig.nodeactyl && themeConfig.admin?.pterodactyl?.enabled) return res.send( 'Unable to contact Pterodactyl, are your details correct?' ) async function getServers() { - if (!themeConfig.admin.pterodactyl.enabled) return [] + if (!themeConfig?.admin?.pterodactyl?.enabled) return [] const serverData = [] - for (const uuid of themeConfig.admin.pterodactyl.serverUUIDs) { - let dataStatus = await pterodactyl.getServerStatus(uuid) - let data = await pterodactyl.getServerDetails(uuid) + for (const uuid of themeConfig?.admin?.pterodactyl?.serverUUIDs) { + let dataStatus = await themeConfig?.nodeactyl?.getServerStatus(uuid) + let data = await themeConfig?.nodeactyl?.getServerDetails(uuid) + serverData.push({ name: data.name.toString(), uuid: data.uuid.toString(), @@ -42,7 +38,7 @@ module.exports = { sData: d, ldata: await database.get('logs'), themeConfig: req.themeConfig, - node: pterodactyl, + node: themeConfig.nodeactyl, bot: config.bot, allFeedsUsed, config, diff --git a/pages/get/debug.js b/pages/get/debug.js index e2f2fe4f..09c68f48 100644 --- a/pages/get/debug.js +++ b/pages/get/debug.js @@ -10,7 +10,7 @@ module.exports = { It will be used with support in the discord server. */ if (!req.session.user) return res.redirect('/discord?r=/debug/') - if (!config.ownerIDs.includes(req.session.user.id)) + if (!config.ownerIDs?.includes(req.session.user.id)) return res.redirect('/') let onlineFiles = { diff --git a/pages/get/settings.js b/pages/get/settings.js index cc48c0ba..373df8f4 100644 --- a/pages/get/settings.js +++ b/pages/get/settings.js @@ -1,7 +1,7 @@ module.exports = { page: '/settings/:id/:category', execute: async (req, res, app, config, themeConfig, info) => { - const categoryExists = config.settings.find( + const categoryExists = config.settings?.find( (s) => s.categoryId === req.params.category ) if (!categoryExists) return config.errorPage(req, res, null, 404) diff --git a/pages/post/guildSettings.js b/pages/post/guildSettings.js index 35230aef..29828bb7 100644 --- a/pages/post/guildSettings.js +++ b/pages/post/guildSettings.js @@ -18,7 +18,7 @@ module.exports = { .members.cache.get(req.session.user.id) const guildObject = config.bot.guilds.cache.get(req.params.guildId) - let category = config.settings.find((c) => c.categoryId == req.query.categoryId) + let category = config.settings?.find((c) => c.categoryId == req.query.categoryId) if (!category) return res.send({ @@ -31,7 +31,7 @@ module.exports = { if (data.categoryToggle) { for (const s of data.categoryToggle) { if (!config.useCategorySet) try { - let category = config.settings.find( + let category = config.settings?.find( (c) => c?.categoryId == s.id ) await category.setNew({ @@ -425,7 +425,7 @@ module.exports = { } if (config.useCategorySet && catToggle.length) for (const opt of catToggle) { - let cat = config.settings.find((c) => c.categoryId == opt.optionId); + let cat = config.settings?.find((c) => c.categoryId == opt.optionId); if (!cat) { errors.push(`Category ${opt.optionId} %is%Doesn't exist%is%categoryToggle`); diff --git a/pages/post/logs.js b/pages/post/logs.js index a52479ff..5e4543da 100644 --- a/pages/post/logs.js +++ b/pages/post/logs.js @@ -2,7 +2,7 @@ module.exports = { page: '/stats/logs/update', execute: async (req, res, app, config, themeConfig, info, db) => { if ( - 'Bearer ' + themeConfig.admin.logs?.key !== + 'Bearer ' + themeConfig.admin?.logs?.key !== req.headers.authorization ) return res.json({ status: 'Invalid sharding key' }) diff --git a/utils/functions/settingsPage.js b/utils/functions/settingsPage.js index 03468a9b..f401fd2e 100644 --- a/utils/functions/settingsPage.js +++ b/utils/functions/settingsPage.js @@ -55,7 +55,7 @@ module.exports = function (config, themeConfig) { let canUseList = {} - if (config.settings.length) for (const category of config.settings) { + if (config.settings?.length) for (const category of config.settings) { if (!canUseList[category.categoryId]) canUseList[category.categoryId] = {}; if (!actual[category.categoryId]) actual[category.categoryId] = {} @@ -300,7 +300,7 @@ module.exports = function (config, themeConfig) { const guild = bot.guilds.cache.get(req.params.id) let gIcon - if (!guild.iconURL()) gIcon = themeConfig.icons.noGuildIcon + if (!guild.iconURL()) gIcon = themeConfig?.icons?.noGuildIcon else gIcon = guild.iconURL() res.render('settings', { diff --git a/utils/initPages.js b/utils/initPages.js index 6add2aa1..f4859fa8 100644 --- a/utils/initPages.js +++ b/utils/initPages.js @@ -1,11 +1,24 @@ const fs = require('fs') const colors = require('colors') const consolePrefix = `${'['.blue}${'dbd-soft-ui'.yellow}${']'.blue} ` +const Nodeactyl = require('nodeactyl') module.exports = { init: async function (config, themeConfig, app, db) { let info; if (themeConfig?.customThemeOptions?.info) info = await themeConfig.customThemeOptions.info({ config: config }); + if(themeConfig?.admin?.pterodactyl?.enabled) { + themeConfig.nodeactyl = new Nodeactyl.NodeactylClient( + themeConfig.admin?.pterodactyl?.panelLink, + themeConfig.admin?.pterodactyl?.apiKey + ) + + try { + await themeConfig.nodeactyl.getAccountDetails(); + } catch (error) { + console.log(`${consolePrefix}${('Failed to connect to Pterodactyl panel!\nEnsure you\'ve used a CLIENT api key, (found at ' + themeConfig.admin.pterodactyl.panelLink + '/account/api)').red}`); + } + } const eventFolders = fs.readdirSync(`${__dirname}/../pages`) for (const folder of eventFolders) { @@ -18,7 +31,7 @@ module.exports = { if (folder === 'admin') { await app.get(e.page, async function (req, res) { if (!req.session.user) return res.sendStatus(401) - if (!config.ownerIDs.includes(req.session.user.id)) return res.sendStatus(403); + if (!config.ownerIDs?.includes(req.session.user.id)) return res.sendStatus(403); e.execute( req, res, diff --git a/views/admin.ejs b/views/admin.ejs index 235c95cc..d604aa55 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -357,7 +357,7 @@
<% - if(themeConfig.admin.pterodactyl.enabled) { %> + if(themeConfig?.admin?.pterodactyl?.enabled) { %>

<% } %> - <% if (themeConfig.admin.logs?.enabled) { %> + <% if (themeConfig.admin?.logs?.enabled) { %>
Bot Logs
diff --git a/views/commands.ejs b/views/commands.ejs index 58d0eef2..1702edbd 100644 --- a/views/commands.ejs +++ b/views/commands.ejs @@ -31,7 +31,7 @@ $('.active_all').addClass('active'); return false; }); - <% themeConfig.commands.forEach(category => { %> + <% themeConfig.commands?.forEach(category => { %> $('#<%= category.categoryId %>').click(function () { $('.item').not('.<%= category.categoryId %>').slideUp(300); $('.<%= category.categoryId %>').slideDown("slow"); @@ -55,7 +55,7 @@
- <% themeConfig.commands.forEach(category => { %> + <% themeConfig.commands?.forEach(category => { %>
diff --git a/views/credits.ejs b/views/credits.ejs index b041f9ef..9e0261ce 100644 --- a/views/credits.ejs +++ b/views/credits.ejs @@ -49,8 +49,7 @@

Soft-UI Theme

Soft UI Theme
-

The Discord-Dashboard Soft UI theme was created as a feature packed theme - that provides lots of bla bla

+

The Discord-Dashboard Soft UI theme was created as a feature-packed theme for DBD users!

Made with by

-
- <% if (error !== undefined && error && config.ownerIDs.includes(req.session?.user?.id) && !themeConfig?.error?.dbdError?.disableSecretMenu) { %> + <% if (error !== undefined && error && config.ownerIDs?.includes(req.session?.user?.id) && !themeConfig?.error?.dbdError?.disableSecretMenu) { %>