mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
Format all files
This commit is contained in:
@@ -25,7 +25,9 @@ export default async function migration() {
|
||||
|
||||
console.log(`Added new table and column: resourceRules, applyRules`);
|
||||
} catch (e) {
|
||||
console.log("Unable to add new table and column: resourceRules, applyRules");
|
||||
console.log(
|
||||
"Unable to add new table and column: resourceRules, applyRules"
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,4 +38,4 @@ export default async function migration() {
|
||||
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
||||
|
||||
console.log("Done.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,9 @@ export default async function migration() {
|
||||
const updatedYaml = yaml.dump(rawConfig);
|
||||
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
||||
} catch (error) {
|
||||
console.log("We were unable to add CORS to your config file. Please add it manually.");
|
||||
console.log(
|
||||
"We were unable to add CORS to your config file. Please add it manually."
|
||||
);
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,12 +182,15 @@ export default async function migration() {
|
||||
|
||||
if (parsedConfig.success) {
|
||||
// delete permanent from redirect-to-https middleware
|
||||
delete traefikConfig.http.middlewares["redirect-to-https"].redirectScheme.permanent;
|
||||
delete traefikConfig.http.middlewares["redirect-to-https"]
|
||||
.redirectScheme.permanent;
|
||||
|
||||
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
||||
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
||||
|
||||
console.log("Deleted permanent from redirect-to-https middleware.");
|
||||
console.log(
|
||||
"Deleted permanent from redirect-to-https middleware."
|
||||
);
|
||||
} else {
|
||||
console.log(fromZodError(parsedConfig.error));
|
||||
console.log(
|
||||
|
||||
@@ -13,15 +13,11 @@ export default async function migration() {
|
||||
|
||||
try {
|
||||
const resources = db
|
||||
.prepare(
|
||||
"SELECT resourceId FROM resources"
|
||||
)
|
||||
.prepare("SELECT resourceId FROM resources")
|
||||
.all() as Array<{ resourceId: number }>;
|
||||
|
||||
const siteResources = db
|
||||
.prepare(
|
||||
"SELECT siteResourceId FROM siteResources"
|
||||
)
|
||||
.prepare("SELECT siteResourceId FROM siteResources")
|
||||
.all() as Array<{ siteResourceId: number }>;
|
||||
|
||||
db.transaction(() => {
|
||||
@@ -82,17 +78,13 @@ export default async function migration() {
|
||||
|
||||
// Handle auto-provisioned users for identity providers
|
||||
const autoProvisionIdps = db
|
||||
.prepare(
|
||||
"SELECT idpId FROM idp WHERE autoProvision = 1"
|
||||
)
|
||||
.prepare("SELECT idpId FROM idp WHERE autoProvision = 1")
|
||||
.all() as Array<{ idpId: number }>;
|
||||
|
||||
for (const idp of autoProvisionIdps) {
|
||||
// Get all users with this identity provider
|
||||
const usersWithIdp = db
|
||||
.prepare(
|
||||
"SELECT id FROM user WHERE idpId = ?"
|
||||
)
|
||||
.prepare("SELECT id FROM user WHERE idpId = ?")
|
||||
.all(idp.idpId) as Array<{ id: string }>;
|
||||
|
||||
// Update userOrgs to set autoProvisioned to true for these users
|
||||
|
||||
@@ -5,16 +5,16 @@ import path from "path";
|
||||
const version = "1.10.1";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
|
||||
try {
|
||||
db.pragma("foreign_keys = OFF");
|
||||
try {
|
||||
db.pragma("foreign_keys = OFF");
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`ALTER TABLE "targets" RENAME TO "targets_old";
|
||||
db.transaction(() => {
|
||||
db.exec(`ALTER TABLE "targets" RENAME TO "targets_old";
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "targets" (
|
||||
"targetId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -57,13 +57,13 @@ SELECT
|
||||
FROM "targets_old";
|
||||
--> statement-breakpoint
|
||||
DROP TABLE "targets_old";`);
|
||||
})();
|
||||
})();
|
||||
|
||||
db.pragma("foreign_keys = ON");
|
||||
db.pragma("foreign_keys = ON");
|
||||
|
||||
console.log(`Migrated database`);
|
||||
} catch (e) {
|
||||
console.log("Failed to migrate db:", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
console.log(`Migrated database`);
|
||||
} catch (e) {
|
||||
console.log("Failed to migrate db:", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,29 @@ export default async function migration() {
|
||||
const db = new Database(location);
|
||||
|
||||
db.transaction(() => {
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'account' (
|
||||
'accountId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'userId' text NOT NULL,
|
||||
FOREIGN KEY ('userId') REFERENCES 'user'('id') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'accountDomains' (
|
||||
'accountId' integer NOT NULL,
|
||||
'domainId' text NOT NULL,
|
||||
FOREIGN KEY ('accountId') REFERENCES 'account'('accountId') ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY ('domainId') REFERENCES 'domains'('domainId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'certificates' (
|
||||
'certId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'domain' text NOT NULL,
|
||||
@@ -49,11 +53,15 @@ export default async function migration() {
|
||||
'keyFile' text,
|
||||
FOREIGN KEY ('domainId') REFERENCES 'domains'('domainId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`CREATE UNIQUE INDEX 'certificates_domain_unique' ON 'certificates' ('domain');`).run();
|
||||
db.prepare(
|
||||
`CREATE UNIQUE INDEX 'certificates_domain_unique' ON 'certificates' ('domain');`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'customers' (
|
||||
'customerId' text PRIMARY KEY NOT NULL,
|
||||
'orgId' text NOT NULL,
|
||||
@@ -65,9 +73,11 @@ export default async function migration() {
|
||||
'updatedAt' integer NOT NULL,
|
||||
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'dnsChallenges' (
|
||||
'dnsChallengeId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'domain' text NOT NULL,
|
||||
@@ -77,26 +87,32 @@ export default async function migration() {
|
||||
'expiresAt' integer NOT NULL,
|
||||
'completed' integer DEFAULT false
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'domainNamespaces' (
|
||||
'domainNamespaceId' text PRIMARY KEY NOT NULL,
|
||||
'domainId' text NOT NULL,
|
||||
FOREIGN KEY ('domainId') REFERENCES 'domains'('domainId') ON UPDATE no action ON DELETE set null
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'exitNodeOrgs' (
|
||||
'exitNodeId' integer NOT NULL,
|
||||
'orgId' text NOT NULL,
|
||||
FOREIGN KEY ('exitNodeId') REFERENCES 'exitNodes'('exitNodeId') ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'loginPage' (
|
||||
'loginPageId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'subdomain' text,
|
||||
@@ -106,27 +122,33 @@ export default async function migration() {
|
||||
FOREIGN KEY ('exitNodeId') REFERENCES 'exitNodes'('exitNodeId') ON UPDATE no action ON DELETE set null,
|
||||
FOREIGN KEY ('domainId') REFERENCES 'domains'('domainId') ON UPDATE no action ON DELETE set null
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'loginPageOrg' (
|
||||
'loginPageId' integer NOT NULL,
|
||||
'orgId' text NOT NULL,
|
||||
FOREIGN KEY ('loginPageId') REFERENCES 'loginPage'('loginPageId') ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'remoteExitNodeSession' (
|
||||
'id' text PRIMARY KEY NOT NULL,
|
||||
'remoteExitNodeId' text NOT NULL,
|
||||
'expiresAt' integer NOT NULL,
|
||||
FOREIGN KEY ('remoteExitNodeId') REFERENCES 'remoteExitNode'('id') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'remoteExitNode' (
|
||||
'id' text PRIMARY KEY NOT NULL,
|
||||
'secretHash' text NOT NULL,
|
||||
@@ -135,9 +157,11 @@ export default async function migration() {
|
||||
'exitNodeId' integer,
|
||||
FOREIGN KEY ('exitNodeId') REFERENCES 'exitNodes'('exitNodeId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'sessionTransferToken' (
|
||||
'token' text PRIMARY KEY NOT NULL,
|
||||
'sessionId' text NOT NULL,
|
||||
@@ -145,9 +169,11 @@ export default async function migration() {
|
||||
'expiresAt' integer NOT NULL,
|
||||
FOREIGN KEY ('sessionId') REFERENCES 'session'('id') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'subscriptionItems' (
|
||||
'subscriptionItemId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'subscriptionId' text NOT NULL,
|
||||
@@ -162,9 +188,11 @@ export default async function migration() {
|
||||
'name' text,
|
||||
FOREIGN KEY ('subscriptionId') REFERENCES 'subscriptions'('subscriptionId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'subscriptions' (
|
||||
'subscriptionId' text PRIMARY KEY NOT NULL,
|
||||
'customerId' text NOT NULL,
|
||||
@@ -175,9 +203,11 @@ export default async function migration() {
|
||||
'billingCycleAnchor' integer,
|
||||
FOREIGN KEY ('customerId') REFERENCES 'customers'('customerId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'usage' (
|
||||
'usageId' text PRIMARY KEY NOT NULL,
|
||||
'featureId' text NOT NULL,
|
||||
@@ -191,9 +221,11 @@ export default async function migration() {
|
||||
'nextRolloverAt' integer,
|
||||
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'usageNotifications' (
|
||||
'notificationId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'orgId' text NOT NULL,
|
||||
@@ -203,18 +235,22 @@ export default async function migration() {
|
||||
'sentAt' integer NOT NULL,
|
||||
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'resourceHeaderAuth' (
|
||||
'headerAuthId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'resourceId' integer NOT NULL,
|
||||
'headerAuthHash' text NOT NULL,
|
||||
FOREIGN KEY ('resourceId') REFERENCES 'resources'('resourceId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'targetHealthCheck' (
|
||||
'targetHealthCheckId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
'targetId' integer NOT NULL,
|
||||
@@ -234,11 +270,13 @@ export default async function migration() {
|
||||
'hcHealth' text DEFAULT 'unknown',
|
||||
FOREIGN KEY ('targetId') REFERENCES 'targets'('targetId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`DROP TABLE 'limits';`).run();
|
||||
|
||||
db.prepare(`
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'limits' (
|
||||
'limitId' text PRIMARY KEY NOT NULL,
|
||||
'featureId' text NOT NULL,
|
||||
@@ -247,12 +285,15 @@ export default async function migration() {
|
||||
'description' text,
|
||||
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
`).run();
|
||||
`
|
||||
).run();
|
||||
|
||||
db.prepare(`ALTER TABLE 'orgs' ADD 'settings' text;`).run();
|
||||
db.prepare(`ALTER TABLE 'targets' ADD 'rewritePath' text;`).run();
|
||||
db.prepare(`ALTER TABLE 'targets' ADD 'rewritePathType' text;`).run();
|
||||
db.prepare(`ALTER TABLE 'targets' ADD 'priority' integer DEFAULT 100 NOT NULL;`).run();
|
||||
db.prepare(
|
||||
`ALTER TABLE 'targets' ADD 'priority' integer DEFAULT 100 NOT NULL;`
|
||||
).run();
|
||||
|
||||
const webauthnCredentials = db
|
||||
.prepare(
|
||||
@@ -269,7 +310,7 @@ export default async function migration() {
|
||||
dateCreated: string;
|
||||
}[];
|
||||
|
||||
db.prepare(`DELETE FROM 'webauthnCredentials';`).run();
|
||||
db.prepare(`DELETE FROM 'webauthnCredentials';`).run();
|
||||
|
||||
for (const webauthnCredential of webauthnCredentials) {
|
||||
const newCredentialId = isoBase64URL.fromBuffer(
|
||||
@@ -304,7 +345,9 @@ export default async function migration() {
|
||||
).run();
|
||||
|
||||
// 2. Select all rows
|
||||
const resources = db.prepare(`SELECT resourceId FROM resources`).all() as {
|
||||
const resources = db
|
||||
.prepare(`SELECT resourceId FROM resources`)
|
||||
.all() as {
|
||||
resourceId: number;
|
||||
}[];
|
||||
|
||||
|
||||
@@ -112,7 +112,6 @@ export default async function migration() {
|
||||
`
|
||||
).run();
|
||||
|
||||
|
||||
db.prepare(
|
||||
`
|
||||
CREATE TABLE 'blueprints' (
|
||||
@@ -212,10 +211,14 @@ export default async function migration() {
|
||||
db.prepare(
|
||||
`ALTER TABLE 'user' ADD 'lastPasswordChange' integer;`
|
||||
).run();
|
||||
db.prepare(`ALTER TABLE 'remoteExitNode' ADD 'secondaryVersion' text;`).run();
|
||||
db.prepare(
|
||||
`ALTER TABLE 'remoteExitNode' ADD 'secondaryVersion' text;`
|
||||
).run();
|
||||
|
||||
// get all of the domains
|
||||
const domains = db.prepare(`SELECT domainId, baseDomain from domains`).all() as {
|
||||
const domains = db
|
||||
.prepare(`SELECT domainId, baseDomain from domains`)
|
||||
.all() as {
|
||||
domainId: number;
|
||||
baseDomain: string;
|
||||
}[];
|
||||
|
||||
@@ -287,7 +287,10 @@ export default async function migration() {
|
||||
let aliasIpOctet = 8;
|
||||
for (const siteResource of siteResourcesForAlias) {
|
||||
const aliasAddress = `100.96.128.${aliasIpOctet}`;
|
||||
updateAliasAddress.run(aliasAddress, siteResource.siteResourceId);
|
||||
updateAliasAddress.run(
|
||||
aliasAddress,
|
||||
siteResource.siteResourceId
|
||||
);
|
||||
aliasIpOctet++;
|
||||
}
|
||||
|
||||
@@ -303,7 +306,12 @@ export default async function migration() {
|
||||
for (const subnet of subnets) {
|
||||
// Generate a unique niceId for each new site resource
|
||||
let niceId = generateName();
|
||||
insertCidrResource.run(site.siteId, subnet.trim(), niceId, site.siteId);
|
||||
insertCidrResource.run(
|
||||
site.siteId,
|
||||
subnet.trim(),
|
||||
niceId,
|
||||
site.siteId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ export default async function migration() {
|
||||
const rawConfig = yaml.load(fileContents) as any;
|
||||
|
||||
if (rawConfig.cors?.headers) {
|
||||
const headers = JSON.parse(
|
||||
JSON.stringify(rawConfig.cors.headers)
|
||||
);
|
||||
const headers = JSON.parse(JSON.stringify(rawConfig.cors.headers));
|
||||
rawConfig.cors.allowed_headers = headers;
|
||||
delete rawConfig.cors.headers;
|
||||
}
|
||||
@@ -61,9 +59,7 @@ export default async function migration() {
|
||||
|
||||
console.log(`Migrated CORS headers to allowed_headers`);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`Unable to migrate config file. Error: ${e}`
|
||||
);
|
||||
console.log(`Unable to migrate config file. Error: ${e}`);
|
||||
}
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
|
||||
@@ -58,7 +58,9 @@ export default async function migration() {
|
||||
|
||||
console.log(`Set trust_proxy to 1 in config file`);
|
||||
} catch (e) {
|
||||
console.log(`Unable to migrate config file. Please do it manually. Error: ${e}`);
|
||||
console.log(
|
||||
`Unable to migrate config file. Please do it manually. Error: ${e}`
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
|
||||
@@ -11,26 +11,28 @@ export default async function migration() {
|
||||
const db = new Database(location);
|
||||
|
||||
const resourceSiteMap = new Map<number, number>();
|
||||
let firstSiteId: number = 1;
|
||||
let firstSiteId: number = 1;
|
||||
|
||||
try {
|
||||
// Get the first siteId to use as default
|
||||
const firstSite = db.prepare("SELECT siteId FROM sites LIMIT 1").get() as { siteId: number } | undefined;
|
||||
if (firstSite) {
|
||||
firstSiteId = firstSite.siteId;
|
||||
}
|
||||
try {
|
||||
// Get the first siteId to use as default
|
||||
const firstSite = db
|
||||
.prepare("SELECT siteId FROM sites LIMIT 1")
|
||||
.get() as { siteId: number } | undefined;
|
||||
if (firstSite) {
|
||||
firstSiteId = firstSite.siteId;
|
||||
}
|
||||
|
||||
const resources = db
|
||||
.prepare(
|
||||
"SELECT resourceId, siteId FROM resources WHERE siteId IS NOT NULL"
|
||||
)
|
||||
.all() as Array<{ resourceId: number; siteId: number }>;
|
||||
for (const resource of resources) {
|
||||
resourceSiteMap.set(resource.resourceId, resource.siteId);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error getting resources:", e);
|
||||
}
|
||||
const resources = db
|
||||
.prepare(
|
||||
"SELECT resourceId, siteId FROM resources WHERE siteId IS NOT NULL"
|
||||
)
|
||||
.all() as Array<{ resourceId: number; siteId: number }>;
|
||||
for (const resource of resources) {
|
||||
resourceSiteMap.set(resource.resourceId, resource.siteId);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error getting resources:", e);
|
||||
}
|
||||
|
||||
try {
|
||||
db.pragma("foreign_keys = OFF");
|
||||
|
||||
Reference in New Issue
Block a user