Skip to content

Commit

Permalink
Bug fixes + additions
Browse files Browse the repository at this point in the history
  • Loading branch information
PlainDevelopment committed Mar 18, 2023
1 parent 6fcd251 commit c00ef22
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 78 deletions.
4 changes: 4 additions & 0 deletions dbd-soft-ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ declare module "dbd-soft-ui" {
}
supporteMail: string,
locales: Record<string, any>,
footer: {
replaceDefault: boolean,
text: string,
}
admin: {
pterodactyl: {
enabled: boolean,
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 5 additions & 10 deletions pages/admin/control.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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')
Expand Down
20 changes: 8 additions & 12 deletions pages/get/admin.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pages/get/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion pages/get/settings.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pages/post/guildSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down Expand Up @@ -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`);
Expand Down
2 changes: 1 addition & 1 deletion pages/post/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
4 changes: 2 additions & 2 deletions utils/functions/settingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}

Expand Down Expand Up @@ -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', {
Expand Down
15 changes: 14 additions & 1 deletion utils/initPages.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions views/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
<!-- End Navbar -->
<div class="container-fluid py-4" style="padding-bottom: 0px !important;">
<%
if(themeConfig.admin.pterodactyl.enabled) { %>
if(themeConfig?.admin?.pterodactyl?.enabled) { %>
<div class="row">
<div class="modal fade" id="modal-notification" tabindex="-1" role="dialog"
aria-labelledby="modal-notification" aria-hidden="true">
Expand Down Expand Up @@ -493,7 +493,7 @@
</div>
<br>
<% } %>
<% if (themeConfig.admin.logs?.enabled) { %>
<% if (themeConfig.admin?.logs?.enabled) { %>
<div class="card h-100">
<div class="card-header pb-0 p-3">
<h6 class="mb-0">Bot Logs</h6>
Expand Down
4 changes: 2 additions & 2 deletions views/commands.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -55,7 +55,7 @@
<div class="container-fluid py-4">
<div class="row">
<div class="container-fluid">
<% themeConfig.commands.forEach(category => { %>
<% themeConfig.commands?.forEach(category => { %>
<section id="<%= category.categoryId %>">
<div class="col-12 item <%= category.categoryId %>" id="divtable">
<div class="card mb-4 command-card">
Expand Down
26 changes: 1 addition & 25 deletions views/credits.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
<div class="d-flex flex-column h-100">
<p class="mb-1 pt-2 text-bold">Soft-UI Theme</p>
<h5 class="font-weight-bolder">Soft UI Theme</h5>
<p>The Discord-Dashboard Soft UI theme was created as a feature packed theme
that provides lots of bla bla</p>
<p>The Discord-Dashboard Soft UI theme was created as a feature-packed theme for DBD users!</p>
<p class="mb-1 mt-5"> Made with <i class="fa fa-heart"></i> by <a
href="https://github.com/PlainDevelopment"
class="font-weight-bold text-gradient text-primary"
Expand Down Expand Up @@ -102,29 +101,6 @@
</div>
</div>
</div>
<div class="card" style="width: 300px; height: 465px; text-align: center;">
<div class="p-3">
<img class="img border-radius-lg max-width-200 w-100 position-relative z-index-2"
src="https://avatars.githubusercontent.com/u/47569748?v=4"
style="width: 200px; height: 200px;"
alt="ArtificialAI">
</div>
<hr>
<div>
<div class="p-3 text-center" style="text-align: left !important; padding-top: 0 !important;">
<h2 class="text-gradient text-primary">ArtificialAI</h2>
<h5 class="mt-1" style="margin-bottom: 0;">Soft UI Developer</h5>
<p>MY EYES HURT</p>
<div style="position: absolute; bottom: 15px;">
<a class="text-body text-bg font-weight-bold mb-0 icon-move-right"
href="https://github.com/artificialai223">
ArtificialAI's Github
<i class="fas fa-arrow-right text-sm ms-1" aria-hidden="true"></i>
</a>
</div>
</div>
</div>
</div>
<div class="card" style="width: 300px; height: 465px; text-align: center;">
<div class="p-3">
<img class="img border-radius-lg max-width-200 w-100 position-relative z-index-2"
Expand Down
2 changes: 1 addition & 1 deletion views/debug.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{name: "License Type", value: `${license}`},
{name: "Uptime", value: `${filterUptime}`},
{name: "Permissions", value: req.requiredPermissions},
{name: "Redirect URI", value: `${config.redirectUri.includes("/discord/callback")}`}
{name: "Redirect URI", value: `${config.redirectUri?.includes("/discord/callback")}`}
]
let modules = [
Expand Down
8 changes: 4 additions & 4 deletions views/error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<%
let data
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) {
data = "text/json;charset=utf-8," + encodeURIComponent(error) + "\n"
data += `${error.path}`
}
%>
<% 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) { %>
<script>
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
Expand Down Expand Up @@ -93,7 +93,7 @@
</header>
</main>
<%- include('partials/scripts.ejs', {now: "index"}) %>
<% 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) { %>
<div class="modal fade" id="exampleModalSignUp" tabindex="-1" role="dialog" aria-labelledby="exampleModalSignTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document" style="max-width: 700px;">
Expand All @@ -116,7 +116,7 @@
</div>
</div>
</div>
<% 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) { %>
<script>
if (window.addEventListener) {
const konami = <%- JSON.stringify(themeConfig?.error?.dbdError?.secretMenuCombination || ["69", "82", "82", "79", "82"]) %> //this spells error
Expand Down
2 changes: 1 addition & 1 deletion views/guilds.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
const guild = bot.guilds.cache.get(req.session.guilds[i].id);
let icon;
if (!guild.iconURL()) icon = themeConfig.icons.noGuildIcon;
if (!guild.iconURL()) icon = themeConfig?.icons?.noGuildIcon;
else icon = guild.iconURL() + "?size=256";
%>
<a oncontextmenu="window.location='/guild/<%- guild.id %>'; return false;"
Expand Down
2 changes: 1 addition & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</div>
</div>
<div class="col-lg-5 mb-4">
<% if(themeConfig.index.graph.enabled) { %>
<% if(themeConfig.index?.graph?.enabled) { %>
<div class="card z-index-2">
<div class="card-body p-3">
<h5 class="font-weight-bolder"><%- req?.locales?.index?.graph?.title %></h5>
Expand Down
21 changes: 13 additions & 8 deletions views/partials/footer.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<footer class="footer">
<div class="container-fluid">
<div class="row align-items-center justify-content-lg-between">
<div class="col-lg-6 mb-lg-0 mb-4">
<div class="copyright text-center text-sm text-muted text-lg-start">
© <%= new Date().getFullYear() %>, Made with <i class="fa fa-heart"></i> by <a href="/credits" class="font-weight-bold" target="_blank">PlainDevelopment</a> and <a href="/credits" class="font-weight-bold" target="_blank">iMidnight</a>
</div>
</div>
<div class="container-fluid">
<div class="row align-items-center justify-content-lg-between">
<div class="col-lg-6 mb-lg-0 mb-4">
<div class="copyright text-center text-sm text-muted text-lg-start">
© <%= new Date().getFullYear() %>
<% if(themeConfig?.footer?.replaceDefault === true) { %>
<a href="/credits" class="font-weight-bold" target="_blank">Assistants</a><% if(themeConfig?.footer?.text?.length) { %> | <%= themeConfig?.footer?.text %> <% } %>
<% } else { %>
Made with <i class="fa fa-heart"></i> by <a href="/credits" class="font-weight-bold" target="_blank">PlainDevelopment</a> and <a href="/credits" class="font-weight-bold" target="_blank">iMidnight</a>
<% } %>
</div>
</div>
</div>
</footer>
</div>
</footer>
2 changes: 1 addition & 1 deletion views/partials/sidebar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
<span class="nav-link-text ms-1"><%- req?.locales?.partials?.sidebar.pp || "Privacy Policy" %></span>
</a>
</li>
<% if(req.session.user && config.ownerIDs.includes(req.session.user.id)) { %>
<% if(req.session.user && config.ownerIDs?.includes(req.session.user.id)) { %>
<li class="nav-item">
<a class="nav-link <% if(now == 'admin'){ %>active"
<% } else { %>" href='/admin'
Expand Down
2 changes: 1 addition & 1 deletion views/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<a onclick="toggleSidenav()"><i
class="fas fa-times p-3 cursor-pointer text-secondary opacity-5 position-absolute end-0 top-0 d-none d-xl-none"
aria-hidden="true" id="iconSidenav"></i></a>
<a <% if(themeConfig.icons.sidebar.alignCenter) { %> style="text-align: center;"
<a <% if(themeConfig?.icons?.sidebar?.alignCenter) { %> style="text-align: center;"
<% } %>
class="navbar-brand m-0" href="/">
<img src="<%= themeConfig.icons.sidebar.lightUrl %>" class="navbar-brand-img h-100" <%
Expand Down

0 comments on commit c00ef22

Please sign in to comment.