mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-16 04:57:52 +00:00
@@ -30,6 +30,7 @@ import { pickPort } from "@server/routers/target/helpers";
|
|||||||
import { resourcePassword } from "@server/db";
|
import { resourcePassword } from "@server/db";
|
||||||
import { hashPassword } from "@server/auth/password";
|
import { hashPassword } from "@server/auth/password";
|
||||||
import { isValidCIDR, isValidIP, isValidUrlGlobPattern } from "../validators";
|
import { isValidCIDR, isValidIP, isValidUrlGlobPattern } from "../validators";
|
||||||
|
import { get } from "http";
|
||||||
|
|
||||||
export type ProxyResourcesResults = {
|
export type ProxyResourcesResults = {
|
||||||
proxyResource: Resource;
|
proxyResource: Resource;
|
||||||
@@ -544,7 +545,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.toUpperCase()
|
existingRule.value !== getRuleValue(rule.match.toUpperCase(), rule.value)
|
||||||
) {
|
) {
|
||||||
validateRule(rule);
|
validateRule(rule);
|
||||||
await trx
|
await trx
|
||||||
@@ -552,7 +553,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.toUpperCase()
|
value: getRuleValue(rule.match.toUpperCase(), rule.value),
|
||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
eq(resourceRules.ruleId, existingRule.ruleId)
|
eq(resourceRules.ruleId, existingRule.ruleId)
|
||||||
@@ -564,7 +565,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.toUpperCase(),
|
value: getRuleValue(rule.match.toUpperCase(), rule.value),
|
||||||
priority: index + 1 // start priorities at 1
|
priority: index + 1 // start priorities at 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -722,7 +723,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.toUpperCase(),
|
value: getRuleValue(rule.match.toUpperCase(), rule.value),
|
||||||
priority: index + 1 // start priorities at 1
|
priority: index + 1 // start priorities at 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -752,6 +753,14 @@ function getRuleAction(input: string) {
|
|||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRuleValue(match: string, value: string) {
|
||||||
|
// if the match is a country, uppercase the value
|
||||||
|
if (match == "COUNTRY") {
|
||||||
|
return value.toUpperCase();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
function validateRule(rule: any) {
|
function validateRule(rule: any) {
|
||||||
if (rule.match === "cidr") {
|
if (rule.match === "cidr") {
|
||||||
if (!isValidCIDR(rule.value)) {
|
if (!isValidCIDR(rule.value)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user