2022-08-12 11:55:07 +00:00
|
|
|
import { ServerResponse } from "../../js/models"
|
|
|
|
|
import { getapi, postapi } from "../../js/utils"
|
2023-09-24 05:48:54 +02:00
|
|
|
import { UseQueryOptions, useQuery } from "@tanstack/react-query"
|
2022-08-12 11:55:07 +00:00
|
|
|
|
|
|
|
|
export type GeneralStats = {
|
|
|
|
|
services:number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Service = {
|
|
|
|
|
name:string,
|
|
|
|
|
service_id:string,
|
|
|
|
|
active:boolean,
|
|
|
|
|
proto: string,
|
2022-08-12 16:00:58 +00:00
|
|
|
ip_src: string,
|
|
|
|
|
ip_dst: string,
|
2022-08-12 11:55:07 +00:00
|
|
|
proxy_port: number,
|
|
|
|
|
public_port: number,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ServiceAddForm = {
|
|
|
|
|
name:string,
|
|
|
|
|
public_port:number,
|
|
|
|
|
proxy_port:number,
|
|
|
|
|
proto:string,
|
2022-08-12 16:00:58 +00:00
|
|
|
ip_src: string,
|
|
|
|
|
ip_dst: string,
|
2022-08-12 11:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-23 02:02:02 +02:00
|
|
|
export type ServiceAddResponse = ServerResponse & { service_id: string }
|
2022-08-12 11:55:07 +00:00
|
|
|
|
2023-09-24 05:48:54 +02:00
|
|
|
export const queryKey = ["porthijack","services"]
|
|
|
|
|
|
|
|
|
|
export const porthijackServiceQuery = () => useQuery({queryKey, queryFn:porthijack.services})
|
|
|
|
|
|
2022-08-12 11:55:07 +00:00
|
|
|
export const porthijack = {
|
2023-09-24 05:48:54 +02:00
|
|
|
services: async () : Promise<Service[]> => {
|
2022-08-12 11:55:07 +00:00
|
|
|
return await getapi("porthijack/services") as Service[];
|
|
|
|
|
},
|
|
|
|
|
serviceinfo: async (service_id:string) => {
|
|
|
|
|
return await getapi(`porthijack/service/${service_id}`) as Service;
|
|
|
|
|
},
|
|
|
|
|
servicestart: async (service_id:string) => {
|
|
|
|
|
const { status } = await getapi(`porthijack/service/${service_id}/start`) as ServerResponse;
|
|
|
|
|
return status === "ok"?undefined:status
|
|
|
|
|
},
|
|
|
|
|
servicerename: async (service_id:string, name: string) => {
|
|
|
|
|
const { status } = await postapi(`porthijack/service/${service_id}/rename`,{ name }) as ServerResponse;
|
|
|
|
|
return status === "ok"?undefined:status
|
|
|
|
|
},
|
|
|
|
|
servicestop: async (service_id:string) => {
|
|
|
|
|
const { status } = await getapi(`porthijack/service/${service_id}/stop`) as ServerResponse;
|
|
|
|
|
return status === "ok"?undefined:status
|
|
|
|
|
},
|
|
|
|
|
servicesadd: async (data:ServiceAddForm) => {
|
|
|
|
|
return await postapi("porthijack/services/add",data) as ServiceAddResponse;
|
|
|
|
|
},
|
|
|
|
|
servicedelete: async (service_id:string) => {
|
|
|
|
|
const { status } = await getapi(`porthijack/service/${service_id}/delete`) as ServerResponse;
|
|
|
|
|
return status === "ok"?undefined:status
|
|
|
|
|
},
|
2022-08-12 16:00:58 +00:00
|
|
|
changedestination: async (service_id:string, ip_dst:string, proxy_port:number) => {
|
|
|
|
|
return await postapi(`porthijack/service/${service_id}/change-destination`, {proxy_port, ip_dst}) as ServerResponse;
|
2022-08-12 11:55:07 +00:00
|
|
|
}
|
|
|
|
|
}
|