mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-10 20:02:26 +00:00
Fixing various things
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { db } from "@server/db";
|
||||
import { db, dnsRecords } from "@server/db";
|
||||
import { domains, exitNodes, orgDomains, orgs, resources } from "@server/db";
|
||||
import config from "@server/lib/config";
|
||||
import { eq, ne } from "drizzle-orm";
|
||||
@@ -8,7 +8,10 @@ export async function copyInConfig() {
|
||||
const endpoint = config.getRawConfig().gerbil.base_endpoint;
|
||||
const listenPort = config.getRawConfig().gerbil.start_port;
|
||||
|
||||
if (!config.getRawConfig().flags?.disable_config_managed_domains && config.getRawConfig().domains) {
|
||||
if (
|
||||
!config.getRawConfig().flags?.disable_config_managed_domains &&
|
||||
config.getRawConfig().domains
|
||||
) {
|
||||
await copyInDomains();
|
||||
}
|
||||
|
||||
@@ -39,7 +42,7 @@ async function copyInDomains() {
|
||||
domainId: key,
|
||||
baseDomain: value.base_domain.toLowerCase(),
|
||||
certResolver: value.cert_resolver || null,
|
||||
preferWildcardCert: value.prefer_wildcard_cert || null,
|
||||
preferWildcardCert: value.prefer_wildcard_cert || null
|
||||
})
|
||||
);
|
||||
|
||||
@@ -56,31 +59,79 @@ async function copyInDomains() {
|
||||
if (!configDomainKeys.has(existingDomain.domainId)) {
|
||||
await trx
|
||||
.delete(domains)
|
||||
.where(eq(domains.domainId, existingDomain.domainId))
|
||||
.execute();
|
||||
.where(eq(domains.domainId, existingDomain.domainId));
|
||||
await trx
|
||||
.delete(dnsRecords)
|
||||
.where(eq(dnsRecords.domainId, existingDomain.domainId));
|
||||
}
|
||||
}
|
||||
|
||||
for (const { domainId, baseDomain, certResolver, preferWildcardCert } of configDomains) {
|
||||
for (const {
|
||||
domainId,
|
||||
baseDomain,
|
||||
certResolver,
|
||||
preferWildcardCert
|
||||
} of configDomains) {
|
||||
if (existingDomainKeys.has(domainId)) {
|
||||
await trx
|
||||
.update(domains)
|
||||
.set({ baseDomain, verified: true, type: "wildcard", certResolver, preferWildcardCert })
|
||||
.where(eq(domains.domainId, domainId))
|
||||
.execute();
|
||||
} else {
|
||||
await trx
|
||||
.insert(domains)
|
||||
.values({
|
||||
domainId,
|
||||
.set({
|
||||
baseDomain,
|
||||
configManaged: true,
|
||||
type: "wildcard",
|
||||
verified: true,
|
||||
type: "wildcard",
|
||||
certResolver,
|
||||
preferWildcardCert
|
||||
})
|
||||
.execute();
|
||||
.where(eq(domains.domainId, domainId));
|
||||
|
||||
// delete the dns records and add them again to ensure they are correct
|
||||
await trx
|
||||
.delete(dnsRecords)
|
||||
.where(eq(dnsRecords.domainId, domainId));
|
||||
|
||||
await trx.insert(dnsRecords).values([
|
||||
{
|
||||
domainId,
|
||||
recordType: "A",
|
||||
baseDomain,
|
||||
value: "Server IP Address",
|
||||
verified: true
|
||||
},
|
||||
{
|
||||
domainId,
|
||||
recordType: "A",
|
||||
baseDomain,
|
||||
value: "Server IP Address",
|
||||
verified: true
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
await trx.insert(domains).values({
|
||||
domainId,
|
||||
baseDomain,
|
||||
configManaged: true,
|
||||
type: "wildcard",
|
||||
verified: true,
|
||||
certResolver,
|
||||
preferWildcardCert
|
||||
});
|
||||
|
||||
await trx.insert(dnsRecords).values([
|
||||
{
|
||||
domainId,
|
||||
recordType: "A",
|
||||
baseDomain,
|
||||
value: "Server IP Address",
|
||||
verified: true
|
||||
},
|
||||
{
|
||||
domainId,
|
||||
recordType: "A",
|
||||
baseDomain,
|
||||
value: "Server IP Address",
|
||||
verified: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user