2023-08-28 22:36:38 +08:00
|
|
|
import { createForm } from '@felte/solid'
|
|
|
|
import { validator } from '@felte/validator-zod'
|
2023-09-01 14:06:21 +08:00
|
|
|
import { For, Show, createSignal, onMount } from 'solid-js'
|
2023-08-28 22:13:48 +08:00
|
|
|
import { z } from 'zod'
|
2023-08-28 22:36:38 +08:00
|
|
|
import { useRequest } from '~/signals'
|
2023-09-01 14:06:21 +08:00
|
|
|
import type { DNSQuery, Config as IConfig } from '~/types'
|
2023-08-28 22:13:48 +08:00
|
|
|
|
|
|
|
const schema = z.object({
|
|
|
|
port: z.number(),
|
|
|
|
'socks-port': z.number(),
|
|
|
|
'redir-port': z.number(),
|
|
|
|
'tproxy-port': z.number(),
|
|
|
|
'mixed-port': z.number(),
|
|
|
|
})
|
|
|
|
|
2023-08-29 14:44:49 +08:00
|
|
|
export default () => {
|
2023-08-28 22:13:48 +08:00
|
|
|
const request = useRequest()
|
2023-09-01 14:06:21 +08:00
|
|
|
|
|
|
|
const [DNSQueryName, setDNSQueryName] = createSignal('')
|
|
|
|
const [DNSQueryResult, setDNSQueryResult] = createSignal<string[]>([])
|
|
|
|
|
|
|
|
const onDNSQuery = () =>
|
|
|
|
request
|
|
|
|
.get('dns/query', {
|
|
|
|
searchParams: {
|
|
|
|
name: DNSQueryName(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.json<DNSQuery>()
|
|
|
|
.then(({ Answer }) => {
|
|
|
|
setDNSQueryResult(Answer.map(({ data }) => data))
|
|
|
|
})
|
|
|
|
|
2023-08-31 11:15:03 +08:00
|
|
|
const portsList = [
|
2023-08-28 22:13:48 +08:00
|
|
|
{
|
2023-08-31 11:15:03 +08:00
|
|
|
label: 'Http Port',
|
2023-08-28 22:13:48 +08:00
|
|
|
key: 'port',
|
|
|
|
},
|
|
|
|
{
|
2023-08-31 11:15:03 +08:00
|
|
|
label: 'Socks Port',
|
2023-08-28 22:13:48 +08:00
|
|
|
key: 'socks-port',
|
|
|
|
},
|
|
|
|
{
|
2023-08-31 11:15:03 +08:00
|
|
|
label: 'Redir Port',
|
2023-08-28 22:13:48 +08:00
|
|
|
key: 'redir-port',
|
|
|
|
},
|
|
|
|
{
|
2023-08-31 11:15:03 +08:00
|
|
|
label: 'Tproxy Port',
|
2023-08-28 22:13:48 +08:00
|
|
|
key: 'tproxy-port',
|
|
|
|
},
|
|
|
|
{
|
2023-08-31 11:15:03 +08:00
|
|
|
label: 'Mixed Port',
|
2023-08-28 22:13:48 +08:00
|
|
|
key: 'mixed-port',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
const { form, setInitialValues, reset } = createForm<z.infer<typeof schema>>({
|
|
|
|
extend: validator({ schema }),
|
|
|
|
})
|
2023-09-01 14:06:21 +08:00
|
|
|
|
2023-08-28 22:13:48 +08:00
|
|
|
onMount(async () => {
|
|
|
|
const configs = await request.get('configs').json<IConfig>()
|
|
|
|
|
|
|
|
setInitialValues(configs)
|
|
|
|
reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2023-09-01 14:06:21 +08:00
|
|
|
<form
|
|
|
|
class="flex items-center gap-2"
|
|
|
|
onSubmit={(e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
onDNSQuery()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
class="input input-bordered flex-1"
|
|
|
|
value={DNSQueryName()}
|
|
|
|
onSubmit={onDNSQuery}
|
|
|
|
onInput={(e) => setDNSQueryName(e.target.value)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<button type="submit" class="btn btn-primary">
|
|
|
|
DNS Query
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<Show when={DNSQueryResult().length > 0}>
|
|
|
|
<div class="flex flex-col p-4">
|
|
|
|
<For each={DNSQueryResult()}>
|
|
|
|
{(item) => <div class="py-2">{item}</div>}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
|
|
|
|
<form class="contents" use:form={form}>
|
2023-08-31 11:15:03 +08:00
|
|
|
<For each={portsList}>
|
2023-08-28 22:13:48 +08:00
|
|
|
{(item) => (
|
2023-08-31 11:15:03 +08:00
|
|
|
<div class="form-control w-64 max-w-xs">
|
|
|
|
<label class="label">
|
|
|
|
<span class="label-text">{item.label}</span>
|
|
|
|
</label>
|
2023-08-28 22:13:48 +08:00
|
|
|
<input
|
|
|
|
name={item.key}
|
2023-08-31 11:15:03 +08:00
|
|
|
type="number"
|
2023-08-28 22:13:48 +08:00
|
|
|
class="input input-bordered"
|
|
|
|
placeholder={item.label}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
)
|
2023-08-24 04:20:53 +08:00
|
|
|
}
|