mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +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))
|
||||
.returning();
|
||||
logger.info(`Updated exit node reachableAt to ${reachableAt}`);
|
||||
}
|
||||
|
||||
return exitNode;
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function createExitNode(publicKey: string, reachableAt: string | un
|
||||
.where(eq(exitNodes.publicKey, publicKey))
|
||||
.returning();
|
||||
|
||||
logger.info(`Updated exit node`);
|
||||
logger.info(`Updated exit node with reachableAt to ${reachableAt}`);
|
||||
}
|
||||
|
||||
return exitNode;
|
||||
|
||||
@@ -117,27 +117,4 @@ export async function generateGerbilConfig(exitNode: ExitNode) {
|
||||
};
|
||||
|
||||
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 { Input } from "@app/components/ui/input";
|
||||
import { Button } from "@app/components/ui/button";
|
||||
import { Checkbox } from "@app/components/ui/checkbox";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { ListSitesResponse } from "@server/routers/site";
|
||||
import { formatAxiosError } from "@app/lib/api";
|
||||
@@ -133,10 +132,6 @@ const tcpUdpResourceFormSchema = z.object({
|
||||
// enableProxy: z.boolean().default(false)
|
||||
});
|
||||
|
||||
const targetsSettingsSchema = z.object({
|
||||
stickySession: z.boolean()
|
||||
});
|
||||
|
||||
const addTargetSchema = z
|
||||
.object({
|
||||
ip: z.string().refine(isTargetValid),
|
||||
@@ -241,7 +236,7 @@ export default function Page() {
|
||||
>([]);
|
||||
const [createLoading, setCreateLoading] = useState(false);
|
||||
const [showSnippets, setShowSnippets] = useState(false);
|
||||
const [resourceId, setResourceId] = useState<number | null>(null);
|
||||
const [niceId, setNiceId] = useState<string>("");
|
||||
|
||||
// Target management state
|
||||
const [targets, setTargets] = useState<LocalTarget[]>([]);
|
||||
@@ -361,17 +356,6 @@ export default function Page() {
|
||||
} 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
|
||||
const areAllTargetsValid = () => {
|
||||
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) => {
|
||||
if (dockerStates.has(siteId)) {
|
||||
return; // Already initialized
|
||||
@@ -531,13 +508,11 @@ export default function Page() {
|
||||
|
||||
const baseData = baseForm.getValues();
|
||||
const isHttp = baseData.http;
|
||||
const stickySessionData = targetsSettingsForm.getValues();
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
name: baseData.name,
|
||||
http: baseData.http,
|
||||
stickySession: stickySessionData.stickySession
|
||||
};
|
||||
|
||||
let sanitizedSubdomain: string | undefined;
|
||||
@@ -583,7 +558,7 @@ export default function Page() {
|
||||
if (res && res.status === 201) {
|
||||
const id = res.data.data.resourceId;
|
||||
const niceId = res.data.data.niceId;
|
||||
setResourceId(id);
|
||||
setNiceId(niceId);
|
||||
|
||||
// Create targets if any exist
|
||||
if (targets.length > 0) {
|
||||
@@ -1905,7 +1880,7 @@ export default function Page() {
|
||||
type="button"
|
||||
onClick={() =>
|
||||
router.push(
|
||||
`/${orgId}/settings/resources/${resourceId}/proxy`
|
||||
`/${orgId}/settings/resources/${niceId}/proxy`
|
||||
)
|
||||
}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user