mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-07 11:16:37 +00:00
Merge pull request #1736 from Lokowitz/fix-geoip-blueprint
fix blueprint country issue - fix #1705 - option 2
This commit is contained in:
@@ -527,7 +527,7 @@ export async function updateProxyResources(
|
|||||||
if (
|
if (
|
||||||
existingRule.action !== getRuleAction(rule.action) ||
|
existingRule.action !== getRuleAction(rule.action) ||
|
||||||
existingRule.match !== rule.match.toUpperCase() ||
|
existingRule.match !== rule.match.toUpperCase() ||
|
||||||
existingRule.value !== rule.value
|
existingRule.value !== rule.value.toUpperCase()
|
||||||
) {
|
) {
|
||||||
validateRule(rule);
|
validateRule(rule);
|
||||||
await trx
|
await trx
|
||||||
@@ -535,7 +535,7 @@ export async function updateProxyResources(
|
|||||||
.set({
|
.set({
|
||||||
action: getRuleAction(rule.action),
|
action: getRuleAction(rule.action),
|
||||||
match: rule.match.toUpperCase(),
|
match: rule.match.toUpperCase(),
|
||||||
value: rule.value
|
value: rule.value.toUpperCase(),
|
||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
eq(resourceRules.ruleId, existingRule.ruleId)
|
eq(resourceRules.ruleId, existingRule.ruleId)
|
||||||
@@ -547,7 +547,7 @@ export async function updateProxyResources(
|
|||||||
resourceId: existingResource.resourceId,
|
resourceId: existingResource.resourceId,
|
||||||
action: getRuleAction(rule.action),
|
action: getRuleAction(rule.action),
|
||||||
match: rule.match.toUpperCase(),
|
match: rule.match.toUpperCase(),
|
||||||
value: rule.value,
|
value: rule.value.toUpperCase(),
|
||||||
priority: index + 1 // start priorities at 1
|
priority: index + 1 // start priorities at 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -705,7 +705,7 @@ export async function updateProxyResources(
|
|||||||
resourceId: newResource.resourceId,
|
resourceId: newResource.resourceId,
|
||||||
action: getRuleAction(rule.action),
|
action: getRuleAction(rule.action),
|
||||||
match: rule.match.toUpperCase(),
|
match: rule.match.toUpperCase(),
|
||||||
value: rule.value,
|
value: rule.value.toUpperCase(),
|
||||||
priority: index + 1 // start priorities at 1
|
priority: index + 1 // start priorities at 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ async function checkRules(
|
|||||||
return rule.action as any;
|
return rule.action as any;
|
||||||
} else if (
|
} else if (
|
||||||
clientIp &&
|
clientIp &&
|
||||||
rule.match == "GEOIP" &&
|
rule.match == "COUNTRY" &&
|
||||||
(await isIpInGeoIP(clientIp, rule.value))
|
(await isIpInGeoIP(clientIp, rule.value))
|
||||||
) {
|
) {
|
||||||
return rule.action as any;
|
return rule.action as any;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { OpenAPITags, registry } from "@server/openApi";
|
|||||||
const createResourceRuleSchema = z
|
const createResourceRuleSchema = z
|
||||||
.object({
|
.object({
|
||||||
action: z.enum(["ACCEPT", "DROP", "PASS"]),
|
action: z.enum(["ACCEPT", "DROP", "PASS"]),
|
||||||
match: z.enum(["CIDR", "IP", "PATH", "GEOIP"]),
|
match: z.enum(["CIDR", "IP", "PATH", "COUNTRY"]),
|
||||||
value: z.string().min(1),
|
value: z.string().min(1),
|
||||||
priority: z.number().int(),
|
priority: z.number().int(),
|
||||||
enabled: z.boolean().optional()
|
enabled: z.boolean().optional()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const updateResourceRuleParamsSchema = z
|
|||||||
const updateResourceRuleSchema = z
|
const updateResourceRuleSchema = z
|
||||||
.object({
|
.object({
|
||||||
action: z.enum(["ACCEPT", "DROP", "PASS"]).optional(),
|
action: z.enum(["ACCEPT", "DROP", "PASS"]).optional(),
|
||||||
match: z.enum(["CIDR", "IP", "PATH", "GEOIP"]).optional(),
|
match: z.enum(["CIDR", "IP", "PATH", "COUNTRY"]).optional(),
|
||||||
value: z.string().min(1).optional(),
|
value: z.string().min(1).optional(),
|
||||||
priority: z.number().int(),
|
priority: z.number().int(),
|
||||||
enabled: z.boolean().optional()
|
enabled: z.boolean().optional()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import m5 from "./scriptsPg/1.10.0";
|
|||||||
import m6 from "./scriptsPg/1.10.2";
|
import m6 from "./scriptsPg/1.10.2";
|
||||||
import m7 from "./scriptsPg/1.11.0";
|
import m7 from "./scriptsPg/1.11.0";
|
||||||
import m8 from "./scriptsPg/1.11.1";
|
import m8 from "./scriptsPg/1.11.1";
|
||||||
|
import m9 from "./scriptsPg/1.11.2";
|
||||||
|
|
||||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||||
@@ -26,7 +27,8 @@ const migrations = [
|
|||||||
{ version: "1.10.0", run: m5 },
|
{ version: "1.10.0", run: m5 },
|
||||||
{ version: "1.10.2", run: m6 },
|
{ version: "1.10.2", run: m6 },
|
||||||
{ version: "1.11.0", run: m7 },
|
{ version: "1.11.0", run: m7 },
|
||||||
{ version: "1.11.1", run: m8 }
|
{ version: "1.11.1", run: m8 },
|
||||||
|
{ version: "1.11.2", run: m9 }
|
||||||
// Add new migrations here as they are created
|
// Add new migrations here as they are created
|
||||||
] as {
|
] as {
|
||||||
version: string;
|
version: string;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import m26 from "./scriptsSqlite/1.10.1";
|
|||||||
import m27 from "./scriptsSqlite/1.10.2";
|
import m27 from "./scriptsSqlite/1.10.2";
|
||||||
import m28 from "./scriptsSqlite/1.11.0";
|
import m28 from "./scriptsSqlite/1.11.0";
|
||||||
import m29 from "./scriptsSqlite/1.11.1";
|
import m29 from "./scriptsSqlite/1.11.1";
|
||||||
|
import m30 from "./scriptsSqlite/1.11.2";
|
||||||
|
|
||||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||||
@@ -60,7 +61,8 @@ const migrations = [
|
|||||||
{ version: "1.10.1", run: m26 },
|
{ version: "1.10.1", run: m26 },
|
||||||
{ version: "1.10.2", run: m27 },
|
{ version: "1.10.2", run: m27 },
|
||||||
{ version: "1.11.0", run: m28 },
|
{ version: "1.11.0", run: m28 },
|
||||||
{ version: "1.11.1", run: m29 }
|
{ version: "1.11.1", run: m29 },
|
||||||
|
{ version: "1.11.2", run: m30 }
|
||||||
// Add new migrations here as they are created
|
// Add new migrations here as they are created
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
|||||||
24
server/setup/scriptsPg/1.11.2.ts
Normal file
24
server/setup/scriptsPg/1.11.2.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { db } from "@server/db/pg/driver";
|
||||||
|
import { sql } from "drizzle-orm";
|
||||||
|
|
||||||
|
const version = "1.11.2";
|
||||||
|
|
||||||
|
export default async function migration() {
|
||||||
|
console.log(`Running setup script ${version}...`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.execute(sql`BEGIN`);
|
||||||
|
|
||||||
|
await db.execute(sql`UPDATE "resourceRules" SET "match" = "COUNTRY" WHERE "match" = "GEOIP"`);
|
||||||
|
|
||||||
|
await db.execute(sql`COMMIT`);
|
||||||
|
console.log(`Updated resource rules match value from GEOIP to COUNTRY`);
|
||||||
|
} catch (e) {
|
||||||
|
await db.execute(sql`ROLLBACK`);
|
||||||
|
console.log("Unable to update resource rules match value");
|
||||||
|
console.log(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${version} migration complete`);
|
||||||
|
}
|
||||||
18
server/setup/scriptsSqlite/1.11.2.ts
Normal file
18
server/setup/scriptsSqlite/1.11.2.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { APP_PATH } from "@server/lib/consts";
|
||||||
|
import Database from "better-sqlite3";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const version = "1.11.2";
|
||||||
|
|
||||||
|
export default async function migration() {
|
||||||
|
console.log(`Running setup script ${version}...`);
|
||||||
|
|
||||||
|
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||||
|
const db = new Database(location);
|
||||||
|
|
||||||
|
db.transaction(() => {
|
||||||
|
db.prepare(`UPDATE resourceRules SET match = "COUNTRY" WHERE match = "GEOIP"`).run();
|
||||||
|
})();
|
||||||
|
|
||||||
|
console.log(`${version} migration complete`);
|
||||||
|
}
|
||||||
@@ -130,7 +130,7 @@ export default function ResourceRules(props: {
|
|||||||
PATH: t('path'),
|
PATH: t('path'),
|
||||||
IP: "IP",
|
IP: "IP",
|
||||||
CIDR: t('ipAddressRange'),
|
CIDR: t('ipAddressRange'),
|
||||||
GEOIP: t('country')
|
COUNTRY: t('country')
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const addRuleForm = useForm({
|
const addRuleForm = useForm({
|
||||||
@@ -212,7 +212,7 @@ export default function ResourceRules(props: {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.match === "GEOIP" && !COUNTRIES.some(c => c.code === data.value)) {
|
if (data.match === "COUNTRY" && !COUNTRIES.some(c => c.code === data.value)) {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: t('rulesErrorInvalidCountry'),
|
title: t('rulesErrorInvalidCountry'),
|
||||||
@@ -270,7 +270,7 @@ export default function ResourceRules(props: {
|
|||||||
return t('rulesMatchIpAddress');
|
return t('rulesMatchIpAddress');
|
||||||
case "PATH":
|
case "PATH":
|
||||||
return t('rulesMatchUrl');
|
return t('rulesMatchUrl');
|
||||||
case "GEOIP":
|
case "COUNTRY":
|
||||||
return t('rulesMatchCountry');
|
return t('rulesMatchCountry');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,8 +492,8 @@ export default function ResourceRules(props: {
|
|||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<Select
|
<Select
|
||||||
defaultValue={row.original.match}
|
defaultValue={row.original.match}
|
||||||
onValueChange={(value: "CIDR" | "IP" | "PATH" | "GEOIP") =>
|
onValueChange={(value: "CIDR" | "IP" | "PATH" | "COUNTRY") =>
|
||||||
updateRule(row.original.ruleId, { match: value, value: value === "GEOIP" ? "US" : row.original.value })
|
updateRule(row.original.ruleId, { match: value, value: value === "COUNTRY" ? "US" : row.original.value })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="min-w-[125px]">
|
<SelectTrigger className="min-w-[125px]">
|
||||||
@@ -504,7 +504,7 @@ export default function ResourceRules(props: {
|
|||||||
<SelectItem value="IP">{RuleMatch.IP}</SelectItem>
|
<SelectItem value="IP">{RuleMatch.IP}</SelectItem>
|
||||||
<SelectItem value="CIDR">{RuleMatch.CIDR}</SelectItem>
|
<SelectItem value="CIDR">{RuleMatch.CIDR}</SelectItem>
|
||||||
{isMaxmindAvailable && (
|
{isMaxmindAvailable && (
|
||||||
<SelectItem value="GEOIP">{RuleMatch.GEOIP}</SelectItem>
|
<SelectItem value="COUNTRY">{RuleMatch.COUNTRY}</SelectItem>
|
||||||
)}
|
)}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
@@ -514,7 +514,7 @@ export default function ResourceRules(props: {
|
|||||||
accessorKey: "value",
|
accessorKey: "value",
|
||||||
header: t('value'),
|
header: t('value'),
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
row.original.match === "GEOIP" ? (
|
row.original.match === "COUNTRY" ? (
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
@@ -748,8 +748,8 @@ export default function ResourceRules(props: {
|
|||||||
{RuleMatch.CIDR}
|
{RuleMatch.CIDR}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
{isMaxmindAvailable && (
|
{isMaxmindAvailable && (
|
||||||
<SelectItem value="GEOIP">
|
<SelectItem value="COUNTRY">
|
||||||
{RuleMatch.GEOIP}
|
{RuleMatch.COUNTRY}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
)}
|
)}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
@@ -775,7 +775,7 @@ export default function ResourceRules(props: {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
{addRuleForm.watch("match") === "GEOIP" ? (
|
{addRuleForm.watch("match") === "COUNTRY" ? (
|
||||||
<Popover open={openAddRuleCountrySelect} onOpenChange={setOpenAddRuleCountrySelect}>
|
<Popover open={openAddRuleCountrySelect} onOpenChange={setOpenAddRuleCountrySelect}>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user