{
diff --git a/src/lib/database/users.ts b/src/lib/database/users.ts
index 5c99143a9..e8d3f8ba6 100644
--- a/src/lib/database/users.ts
+++ b/src/lib/database/users.ts
@@ -12,13 +12,16 @@ export async function login({ email, password }) {
const users = await prisma.user.count();
const userFound = await prisma.user.findUnique({
where: { email },
- include: { teams: true },
+ include: { teams: true, permission: true },
rejectOnNotFound: false
});
+ console.log(userFound);
// Registration disabled if database is not seeded properly
const { isRegistrationEnabled, id } = await db.listSettings();
let uid = cuid();
+ let permission = 'read';
+ let isAdmin = false;
// Disable registration if we are registering the first user.
if (users === 0) {
await prisma.setting.update({ where: { id }, data: { isRegistrationEnabled: false } });
@@ -50,6 +53,8 @@ export async function login({ email, password }) {
};
}
uid = userFound.id;
+ // permission = userFound.permission;
+ isAdmin = true;
}
} else {
// If registration disabled, return 403
@@ -61,6 +66,8 @@ export async function login({ email, password }) {
const hashedPassword = await bcrypt.hash(password, saltRounds);
if (users === 0) {
+ permission = 'owner';
+ isAdmin = true;
await prisma.user.create({
data: {
id: uid,
@@ -103,8 +110,10 @@ export async function login({ email, password }) {
'Set-Cookie': `teamId=${uid}; HttpOnly; Path=/; Max-Age=15778800;`
},
body: {
- uid,
- teamId: uid
+ userId: uid,
+ teamId: uid,
+ permission,
+ isAdmin
}
};
}
diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.ts
index cda1cd1c1..4e14be487 100644
--- a/src/lib/haproxy/index.ts
+++ b/src/lib/haproxy/index.ts
@@ -48,7 +48,8 @@ export async function completeTransaction(transactionId) {
return await haproxy.put(`v2/services/haproxy/transactions/${transactionId}`);
}
-export async function removeProxyConfiguration({ domain }) {
+export async function removeProxyConfiguration(fqdn) {
+ const domain = getDomain(fqdn);
const haproxy = await haproxyInstance();
const backendFound = await haproxy
.get(`v2/services/haproxy/configuration/backends/${domain}`)
@@ -64,10 +65,10 @@ export async function removeProxyConfiguration({ domain }) {
.json();
await completeTransaction(transactionId);
}
- await forceSSLOffApplication({ domain });
- await removeWwwRedirection(domain);
+ await forceSSLOffApplication(domain);
+ await removeWwwRedirection(fqdn);
}
-export async function forceSSLOffApplication({ domain }) {
+export async function forceSSLOffApplication(domain) {
const haproxy = await haproxyInstance();
await checkHAProxy(haproxy);
let transactionId;
@@ -104,7 +105,7 @@ export async function forceSSLOffApplication({ domain }) {
if (transactionId) await completeTransaction(transactionId);
}
}
-export async function forceSSLOnApplication({ domain }) {
+export async function forceSSLOnApplication(domain) {
const haproxy = await haproxyInstance();
await checkHAProxy(haproxy);
let transactionId;
@@ -283,7 +284,7 @@ export async function configureCoolifyProxyOff(fqdn) {
})
.json();
await completeTransaction(transactionId);
- if (isHttps) await forceSSLOffApplication({ domain });
+ if (isHttps) await forceSSLOffApplication(domain);
await removeWwwRedirection(fqdn);
} catch (error) {
throw error?.response?.body || error;
@@ -558,7 +559,8 @@ export async function configureSimpleServiceProxyOn({ id, domain, port }) {
await completeTransaction(transactionId);
}
-export async function configureSimpleServiceProxyOff({ domain }) {
+export async function configureSimpleServiceProxyOff(fqdn) {
+ const domain = getDomain(fqdn);
const haproxy = await haproxyInstance();
await checkHAProxy(haproxy);
try {
@@ -573,12 +575,16 @@ export async function configureSimpleServiceProxyOff({ domain }) {
.json();
await completeTransaction(transactionId);
} catch (error) {}
- await forceSSLOffApplication({ domain });
- await removeWwwRedirection(domain);
+ await forceSSLOffApplication(domain);
+ await removeWwwRedirection(fqdn);
return;
}
-export async function removeWwwRedirection(domain) {
+export async function removeWwwRedirection(fqdn) {
+ const domain = getDomain(fqdn);
+ const isHttps = fqdn.startsWith('https://');
+ const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
+
const haproxy = await haproxyInstance();
await checkHAProxy();
const rules: any = await haproxy
@@ -590,9 +596,7 @@ export async function removeWwwRedirection(domain) {
})
.json();
if (rules.data.length > 0) {
- const rule = rules.data.find((rule) =>
- rule.redir_value.includes(`${domain}%[capture.req.uri]`)
- );
+ const rule = rules.data.find((rule) => rule.redir_value.includes(redirectValue));
if (rule) {
const transactionId = await getNextTransactionId();
await haproxy
@@ -617,6 +621,7 @@ export async function setWwwRedirection(fqdn) {
const domain = getDomain(fqdn);
const isHttps = fqdn.startsWith('https://');
const isWWW = fqdn.includes('www.');
+ const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
const contTest = `{ req.hdr(host) -i ${isWWW ? domain.replace('www.', '') : `www.${domain}`} }`;
const rules: any = await haproxy
.get(`v2/services/haproxy/configuration/http_request_rules`, {
@@ -628,13 +633,11 @@ export async function setWwwRedirection(fqdn) {
.json();
let nextRule = 0;
if (rules.data.length > 0) {
- const rule = rules.data.find((rule) =>
- rule.redir_value.includes(`${domain}%[capture.req.uri]`)
- );
+ const rule = rules.data.find((rule) => rule.redir_value.includes(redirectValue));
if (rule) return;
nextRule = rules.data[rules.data.length - 1].index + 1;
}
- const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
+
transactionId = await getNextTransactionId();
await haproxy
.post(`v2/services/haproxy/configuration/http_request_rules`, {
diff --git a/src/lib/letsencrypt.ts b/src/lib/letsencrypt.ts
index 751b61c3e..b1b2cdee0 100644
--- a/src/lib/letsencrypt.ts
+++ b/src/lib/letsencrypt.ts
@@ -46,35 +46,33 @@ export async function letsEncrypt({ domain, isCoolify = false, id = null }) {
}
}
}
- await forceSSLOffApplication({ domain });
+ await forceSSLOffApplication(domain);
if (dualCerts) {
- const error = await asyncExecShell(
+ await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p ${randomPort}:${randomPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${randomPort} -d ${nakedDomain} -d ${wwwDomain} --expand --agree-tos --non-interactive --register-unsafely-without-email ${
dev ? '--test-cert' : ''
}`
);
- if (error.stderr) throw error;
- const sslCopyError = await asyncExecShell(
+ await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "test -d /etc/letsencrypt/live/${nakedDomain}/ && cat /etc/letsencrypt/live/${nakedDomain}/fullchain.pem /etc/letsencrypt/live/${nakedDomain}/privkey.pem > /app/ssl/${nakedDomain}.pem || cat /etc/letsencrypt/live/${wwwDomain}/fullchain.pem /etc/letsencrypt/live/${wwwDomain}/privkey.pem > /app/ssl/${wwwDomain}.pem"`
);
- if (sslCopyError.stderr) throw sslCopyError;
} else {
- const sslGenerateError = await asyncExecShell(
+ await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p ${randomPort}:${randomPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${randomPort} -d ${domain} --expand --agree-tos --non-interactive --register-unsafely-without-email ${
dev ? '--test-cert' : ''
}`
);
- if (sslGenerateError.stderr) throw sslGenerateError;
- const sslCopyError = await asyncExecShell(
+ await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /app/ssl/${domain}.pem"`
);
- if (sslCopyError.stderr) throw sslCopyError;
}
} catch (error) {
- throw error;
+ if (error.code !== 0) {
+ throw error;
+ }
} finally {
if (!isCoolify) {
- await forceSSLOnApplication({ domain });
+ await forceSSLOnApplication(domain);
}
}
}
diff --git a/src/lib/queues/proxy.ts b/src/lib/queues/proxy.ts
index 92d14f738..36ac37ff9 100644
--- a/src/lib/queues/proxy.ts
+++ b/src/lib/queues/proxy.ts
@@ -48,7 +48,7 @@ export default async function () {
port
});
const isHttps = fqdn.startsWith('https://');
- if (isHttps) await forceSSLOnApplication({ domain });
+ if (isHttps) await forceSSLOnApplication(domain);
await setWwwRedirection(fqdn);
}
}
@@ -98,7 +98,7 @@ export default async function () {
await configureCoolifyProxyOn(fqdn);
await setWwwRedirection(fqdn);
const isHttps = fqdn.startsWith('https://');
- if (isHttps) await forceSSLOnApplication({ domain });
+ if (isHttps) await forceSSLOnApplication(domain);
}
} catch (error) {
console.log(error);
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte
index 027a11e3d..75265e1b0 100644
--- a/src/routes/__layout.svelte
+++ b/src/routes/__layout.svelte
@@ -3,13 +3,13 @@
import { publicPaths } from '$lib/settings';
export const load: Load = async ({ fetch, url, params, session }) => {
- if (!session.uid && !publicPaths.includes(url.pathname)) {
+ if (!session.userId && !publicPaths.includes(url.pathname)) {
return {
status: 302,
redirect: '/login'
};
}
- if (!session.uid) {
+ if (!session.userId) {
return {};
}
const endpoint = `/teams.json`;
@@ -49,7 +49,7 @@
};
let latestVersion = 'latest';
onMount(async () => {
- if ($session.uid) {
+ if ($session.userId) {
const overrideVersion = browser && window.localStorage.getItem('latestVersion');
try {
await get(`/login.json`);
@@ -84,7 +84,7 @@
}
async function switchTeam() {
try {
- await post(`/index.json?from=${$page.url.pathname}`, {
+ await post(`/dashboard.json?from=${$page.url.pathname}`, {
cookie: 'teamId',
value: selectedTeamId
});
@@ -129,7 +129,7 @@
Coolify
-{#if $session.uid}
+{#if $session.userId}