mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-28 07:46:36 +00:00
Handle updating exit node and fix raw resource issues
This commit is contained in:
@@ -69,6 +69,7 @@ export async function createExitNode(
|
|||||||
})
|
})
|
||||||
.where(eq(exitNodes.exitNodeId, exitNodeQuery.exitNodeId))
|
.where(eq(exitNodes.exitNodeId, exitNodeQuery.exitNodeId))
|
||||||
.returning();
|
.returning();
|
||||||
|
logger.info(`Updated exit node reachableAt to ${reachableAt}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitNode;
|
return exitNode;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export async function createExitNode(publicKey: string, reachableAt: string | un
|
|||||||
.where(eq(exitNodes.publicKey, publicKey))
|
.where(eq(exitNodes.publicKey, publicKey))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
logger.info(`Updated exit node`);
|
logger.info(`Updated exit node with reachableAt to ${reachableAt}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitNode;
|
return exitNode;
|
||||||
|
|||||||
@@ -118,26 +118,3 @@ export async function generateGerbilConfig(exitNode: ExitNode) {
|
|||||||
|
|
||||||
return configResponse;
|
return configResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNextAvailablePort(): Promise<number> {
|
|
||||||
// Get all existing ports from exitNodes table
|
|
||||||
const existingPorts = await db
|
|
||||||
.select({
|
|
||||||
listenPort: exitNodes.listenPort
|
|
||||||
})
|
|
||||||
.from(exitNodes);
|
|
||||||
|
|
||||||
// Find the first available port between 1024 and 65535
|
|
||||||
let nextPort = config.getRawConfig().gerbil.start_port;
|
|
||||||
for (const port of existingPorts) {
|
|
||||||
if (port.listenPort > nextPort) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nextPort++;
|
|
||||||
if (nextPort > 65535) {
|
|
||||||
throw new Error("No available ports remaining in space");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nextPort;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import { Controller, useForm } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import { Checkbox } from "@app/components/ui/checkbox";
|
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { ListSitesResponse } from "@server/routers/site";
|
import { ListSitesResponse } from "@server/routers/site";
|
||||||
import { formatAxiosError } from "@app/lib/api";
|
import { formatAxiosError } from "@app/lib/api";
|
||||||
@@ -133,10 +132,6 @@ const tcpUdpResourceFormSchema = z.object({
|
|||||||
// enableProxy: z.boolean().default(false)
|
// enableProxy: z.boolean().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
const targetsSettingsSchema = z.object({
|
|
||||||
stickySession: z.boolean()
|
|
||||||
});
|
|
||||||
|
|
||||||
const addTargetSchema = z
|
const addTargetSchema = z
|
||||||
.object({
|
.object({
|
||||||
ip: z.string().refine(isTargetValid),
|
ip: z.string().refine(isTargetValid),
|
||||||
@@ -241,7 +236,7 @@ export default function Page() {
|
|||||||
>([]);
|
>([]);
|
||||||
const [createLoading, setCreateLoading] = useState(false);
|
const [createLoading, setCreateLoading] = useState(false);
|
||||||
const [showSnippets, setShowSnippets] = useState(false);
|
const [showSnippets, setShowSnippets] = useState(false);
|
||||||
const [resourceId, setResourceId] = useState<number | null>(null);
|
const [niceId, setNiceId] = useState<string>("");
|
||||||
|
|
||||||
// Target management state
|
// Target management state
|
||||||
const [targets, setTargets] = useState<LocalTarget[]>([]);
|
const [targets, setTargets] = useState<LocalTarget[]>([]);
|
||||||
@@ -361,17 +356,6 @@ export default function Page() {
|
|||||||
} as z.infer<typeof addTargetSchema>
|
} as z.infer<typeof addTargetSchema>
|
||||||
});
|
});
|
||||||
|
|
||||||
const targetsSettingsForm = useForm({
|
|
||||||
resolver: zodResolver(targetsSettingsSchema),
|
|
||||||
defaultValues: {
|
|
||||||
stickySession: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const watchedIp = addTargetForm.watch("ip");
|
|
||||||
const watchedPort = addTargetForm.watch("port");
|
|
||||||
const watchedSiteId = addTargetForm.watch("siteId");
|
|
||||||
|
|
||||||
// Helper function to check if all targets have required fields using schema validation
|
// Helper function to check if all targets have required fields using schema validation
|
||||||
const areAllTargetsValid = () => {
|
const areAllTargetsValid = () => {
|
||||||
if (targets.length === 0) return true; // No targets is valid
|
if (targets.length === 0) return true; // No targets is valid
|
||||||
@@ -396,13 +380,6 @@ export default function Page() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleContainerSelect = (hostname: string, port?: number) => {
|
|
||||||
addTargetForm.setValue("ip", hostname);
|
|
||||||
if (port) {
|
|
||||||
addTargetForm.setValue("port", port);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const initializeDockerForSite = async (siteId: number) => {
|
const initializeDockerForSite = async (siteId: number) => {
|
||||||
if (dockerStates.has(siteId)) {
|
if (dockerStates.has(siteId)) {
|
||||||
return; // Already initialized
|
return; // Already initialized
|
||||||
@@ -531,13 +508,11 @@ export default function Page() {
|
|||||||
|
|
||||||
const baseData = baseForm.getValues();
|
const baseData = baseForm.getValues();
|
||||||
const isHttp = baseData.http;
|
const isHttp = baseData.http;
|
||||||
const stickySessionData = targetsSettingsForm.getValues();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
name: baseData.name,
|
name: baseData.name,
|
||||||
http: baseData.http,
|
http: baseData.http,
|
||||||
stickySession: stickySessionData.stickySession
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let sanitizedSubdomain: string | undefined;
|
let sanitizedSubdomain: string | undefined;
|
||||||
@@ -583,7 +558,7 @@ export default function Page() {
|
|||||||
if (res && res.status === 201) {
|
if (res && res.status === 201) {
|
||||||
const id = res.data.data.resourceId;
|
const id = res.data.data.resourceId;
|
||||||
const niceId = res.data.data.niceId;
|
const niceId = res.data.data.niceId;
|
||||||
setResourceId(id);
|
setNiceId(niceId);
|
||||||
|
|
||||||
// Create targets if any exist
|
// Create targets if any exist
|
||||||
if (targets.length > 0) {
|
if (targets.length > 0) {
|
||||||
@@ -1905,7 +1880,7 @@ export default function Page() {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
router.push(
|
router.push(
|
||||||
`/${orgId}/settings/resources/${resourceId}/proxy`
|
`/${orgId}/settings/resources/${niceId}/proxy`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user