This commit is contained in:
Andras Bacsai 2022-11-28 14:29:14 +01:00
parent 37036f0fca
commit 3f078517a0
3 changed files with 31 additions and 24 deletions

View File

@ -9,7 +9,7 @@ import autoLoad from '@fastify/autoload';
import socketIO from 'fastify-socket.io'
import socketIOServer from './realtime'
import { asyncExecShell, cleanupDockerStorage, createRemoteEngineConfiguration, decrypt, encrypt, executeDockerCmd, executeSSHCmd, generateDatabaseConfiguration, isDev, listSettings, prisma, startTraefikProxy, startTraefikTCPProxy, version } from './lib/common';
import { asyncExecShell, cleanupDockerStorage, createRemoteEngineConfiguration, decrypt, executeDockerCmd, executeSSHCmd, generateDatabaseConfiguration, isDev, listSettings, prisma, sentryDSN, startTraefikProxy, startTraefikTCPProxy, version } from './lib/common';
import { scheduler } from './lib/scheduler';
import { compareVersions } from 'compare-versions';
import Graceful from '@ladjs/graceful'
@ -36,7 +36,6 @@ declare module 'fastify' {
const port = isDev ? 3001 : 3000;
const host = '0.0.0.0';
const sentryDSN = 'https://409f09bcb7af47928d3e0f46b78987f3@o1082494.ingest.sentry.io/4504236622217216';
(async () => {
const settings = await prisma.setting.findFirst()
@ -240,39 +239,36 @@ async function getTagsTemplates() {
}
async function initServer() {
const appId = process.env['COOLIFY_APP_ID'];
const settings = await prisma.setting.findUnique({ where: { id: '0' } })
try {
let doNotTrack = false
if (appId === '') {
doNotTrack = true
}
if (appId === '') doNotTrack = true
doNotTrack = settings.doNotTrack
await prisma.setting.update({ where: { id: '0' }, data: { doNotTrack } })
} catch (error) {
console.log(error)
}
try {
const settings = await prisma.setting.findUnique({ where: { id: '0' } })
if (!settings.sentryDSN) {
if (appId == '') {
console.log('Telemetry disabled')
return
} else {
await prisma.setting.update({ where: { id: '0' }, data: { sentryDSN } })
}
if (settings.doNotTrack === true) {
console.log('[000] Telemetry disabled...')
} else {
if (settings.sentryDSN !== sentryDSN) {
await prisma.setting.update({ where: { id: '0' }, data: { sentryDSN } })
}
// Initialize Sentry
Sentry.init({
debug: true,
dsn: sentryDSN,
environment: isDev ? 'development' : 'production',
release: version
});
console.log('[000] Sentry initialized...')
}
// Initialize Sentry
Sentry.init({
dsn: sentryDSN,
environment: isDev ? 'development' : 'production',
release: version
});
} catch (error) {
console.error(error)
}
try {
console.log(`[001] Initializing server...`);
await asyncExecShell(`docker network create --attachable coolify`);

View File

@ -8,6 +8,7 @@ import type { Config } from 'unique-names-generator';
import generator from 'generate-password';
import crypto from 'crypto';
import { promises as dns } from 'dns';
import * as Sentry from '@sentry/node';
import { PrismaClient } from '@prisma/client';
import os from 'os';
import sshConfig from 'ssh-config';
@ -19,7 +20,7 @@ import { scheduler } from './scheduler';
export const version = '3.12.0';
export const isDev = process.env.NODE_ENV === 'development';
export const sentryDSN = 'https://409f09bcb7af47928d3e0f46b78987f3@o1082494.ingest.sentry.io/4504236622217216';
const algorithm = 'aes-256-ctr';
const customConfig: Config = {
dictionaries: [adjectives, colors, animals],
@ -1491,6 +1492,7 @@ export function errorHandler({
message: string | any;
}) {
if (message.message) message = message.message;
Sentry.captureException({ status, message });
throw { status, message };
}
export async function generateSshKeyPair(): Promise<{ publicKey: string; privateKey: string }> {

View File

@ -1,8 +1,8 @@
import { promises as dns } from 'dns';
import { X509Certificate } from 'node:crypto';
import * as Sentry from '@sentry/node';
import type { FastifyReply, FastifyRequest } from 'fastify';
import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, isDev, isDNSValid, isDomainConfigured, listSettings, prisma } from '../../../../lib/common';
import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, isDev, isDNSValid, isDomainConfigured, listSettings, prisma, sentryDSN, version } from '../../../../lib/common';
import { AddDefaultRegistry, CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey, SetDefaultRegistry } from './types';
@ -78,6 +78,15 @@ export async function saveSettings(request: FastifyRequest<SaveSettings>, reply:
if (minPort && maxPort) {
await prisma.setting.update({ where: { id }, data: { minPort, maxPort } });
}
if (doNotTrack === false) {
Sentry.init({
debug: true,
dsn: sentryDSN,
environment: isDev ? 'development' : 'production',
release: version
});
console.log('Sentry initialized')
}
return reply.code(201).send()
} catch ({ status, message }) {
return errorHandler({ status, message })
@ -110,7 +119,7 @@ export async function checkDomain(request: FastifyRequest<CheckDomain>) {
if (fqdn) fqdn = fqdn.toLowerCase();
const found = await isDomainConfigured({ id, fqdn });
if (found) {
throw "Domain already configured";
throw { message: "Domain already configured" };
}
if (isDNSCheckEnabled && !forceSave && !isDev) {
const hostname = request.hostname.split(':')[0]