From 72dec0c080bffa0c5ef4fc7fedfd56dc01e6a401 Mon Sep 17 00:00:00 2001 From: David M <62346025+aboutdavid@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:40:13 -0400 Subject: [PATCH 1/2] make it actually work --- cli/caddy_migrate.js | 2 +- cli/commands/caddy.js | 8 ++++---- cli/index.js | 2 +- cli/prisma/schema.prisma | 4 ++-- cli/utils.js | 5 ++--- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cli/caddy_migrate.js b/cli/caddy_migrate.js index b982c60..c3982eb 100644 --- a/cli/caddy_migrate.js +++ b/cli/caddy_migrate.js @@ -24,7 +24,7 @@ routes.forEach(route => { } }); async function main() { - await prisma.domain.create({ + await prisma.domain.createMany({ data: set }) } diff --git a/cli/commands/caddy.js b/cli/commands/caddy.js index d4afc80..e89429e 100644 --- a/cli/commands/caddy.js +++ b/cli/commands/caddy.js @@ -10,7 +10,7 @@ module.exports = function ({ program, run }) { caddy .command('list') .description('lists all domains you have configured in caddy') - .option('--user', 'allows you to add a domain on behalf of a user (requires sudo)') + .option('--user [user]', 'allows you to add a domain on behalf of a user (requires sudo)') .action(async (options) => { if (options?.user && !isAdmin) { console.error("To change/see another user's domains, you'll need to use sudo or be root.") @@ -25,8 +25,8 @@ module.exports = function ({ program, run }) { caddy .command('add ') .description('adds a domain to caddy') - .option('--proxy', 'changes where the domain should be proxied to (advanced)') - .option('--user', "allows you to list a different user's domains (requires sudo)") + .option('--proxy [proxy]', 'changes where the domain should be proxied to (advanced)') + .option('--user [user]', "allows you to list a different user's domains (requires sudo)") .action(async (domain, options) => { if (options?.user && !isAdmin) { console.error("To change/see another user's domains, you'll need to use sudo or be root.") @@ -68,7 +68,7 @@ module.exports = function ({ program, run }) { caddy .command('rm ') .description('removes a domain from caddy') - .option('--user', 'allows you to add a domain on behalf of a user (requires sudo)') + .option('--user [user]', 'allows you to add a domain on behalf of a user (requires sudo)') .action(async (domain, options) => { if (options?.user && !isAdmin) { console.error("To change/see another user's domains, you'll need to use sudo or be root.") diff --git a/cli/index.js b/cli/index.js index 4b84519..c4af0ae 100755 --- a/cli/index.js +++ b/cli/index.js @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env bun const { Command } = require('commander'); const program = new Command(); const { execSync } = require('child_process'); diff --git a/cli/prisma/schema.prisma b/cli/prisma/schema.prisma index 2f81120..90e8d7c 100644 --- a/cli/prisma/schema.prisma +++ b/cli/prisma/schema.prisma @@ -4,8 +4,8 @@ generator client { } datasource db { - provider = "sqlite" - url = "file:./database.sqlite" + provider = "postgresql" + url = env("DATABASE_URL") } model Domain { diff --git a/cli/utils.js b/cli/utils.js index c3c31c3..24741c7 100644 --- a/cli/utils.js +++ b/cli/utils.js @@ -8,10 +8,9 @@ const isAdmin = !process.getuid() || os.userInfo().username == "nest-internal" module.exports = { checkWhitelist: function (domain, username) { - if (!fs.existsSync(".whitelist")) return - const whitelist = fs.readFileSync(".whitelist", "utf8").split("\n") + if (!fs.existsSync(__dirname + "/.whitelist")) return + const whitelist = fs.readFileSync(__dirname + "/.whitelist", "utf8").split("\n") - whitelist var i = 0 while (i < whitelist.length) { if (minimatch(domain, whitelist[i].replace("$USERNAME", username))) return true From 1ce7675414d5c623dbf50364bb7f228a9b2e2f37 Mon Sep 17 00:00:00 2001 From: David M <62346025+aboutdavid@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:58:01 -0400 Subject: [PATCH 2/2] Update resources for root --- cli/commands/resources.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/commands/resources.js b/cli/commands/resources.js index 6a39ea6..e9063b5 100644 --- a/cli/commands/resources.js +++ b/cli/commands/resources.js @@ -5,6 +5,10 @@ module.exports = function ({ program, run }) { .command('resources') .description('See your Nest resource usage and limits') .action(() => { + if (!process.getuid()){ + console.log("Root doesn't have any limits.") + process.exit(0) + } const output = run(`quota`).toString(); const numbers = output.split("\n").find(line => line.includes("/dev/sda")).match(/\d+/g); const array = numbers.map(Number)