2023-08-28 22:36:38 +08:00
|
|
|
import { createForm } from '@felte/solid'
|
|
|
|
import { validator } from '@felte/validator-zod'
|
2023-09-02 13:54:59 +08:00
|
|
|
import { useI18n } from '@solid-primitives/i18n'
|
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-09-02 13:54:59 +08:00
|
|
|
import { PROXIES_PREVIEW_TYPE } from '~/config/enum'
|
2023-09-02 19:06:02 +08:00
|
|
|
import { themes } from '~/constants'
|
2023-08-28 22:36:38 +08:00
|
|
|
import { useRequest } from '~/signals'
|
2023-09-02 15:55:38 +08:00
|
|
|
import {
|
2023-09-02 19:06:02 +08:00
|
|
|
applyThemeByMode,
|
2023-09-02 15:55:38 +08:00
|
|
|
autoCloseConns,
|
2023-09-02 19:06:02 +08:00
|
|
|
autoSwitchTheme,
|
|
|
|
favDayTheme,
|
|
|
|
favNightTheme,
|
2023-09-02 15:55:38 +08:00
|
|
|
proxiesPreviewType,
|
|
|
|
setAutoCloseConns,
|
2023-09-02 19:06:02 +08:00
|
|
|
setAutoSwitchTheme,
|
|
|
|
setFavDayTheme,
|
|
|
|
setFavNightTheme,
|
2023-09-02 15:55:38 +08:00
|
|
|
setProxiesPreviewType,
|
|
|
|
setUrlForDelayTest,
|
|
|
|
urlForDelayTest,
|
|
|
|
} from '~/signals/config'
|
2023-09-01 14:06:21 +08:00
|
|
|
import type { DNSQuery, Config as IConfig } from '~/types'
|
2023-08-28 22:13:48 +08:00
|
|
|
|
2023-09-02 13:54:59 +08:00
|
|
|
const dnsQueryFormSchema = z.object({
|
|
|
|
name: z.string(),
|
|
|
|
type: z.string(),
|
|
|
|
})
|
|
|
|
|
|
|
|
const DNSQueryForm = () => {
|
|
|
|
const [t] = useI18n()
|
|
|
|
const request = useRequest()
|
|
|
|
|
|
|
|
const { form } = createForm<z.infer<typeof dnsQueryFormSchema>>({
|
|
|
|
extend: validator({ schema: dnsQueryFormSchema }),
|
|
|
|
onSubmit: async (values) => {
|
|
|
|
request
|
|
|
|
.get('dns/query', {
|
|
|
|
searchParams: { name: values.name, type: values.type },
|
|
|
|
})
|
|
|
|
.json<DNSQuery>()
|
|
|
|
.then(({ Answer }) =>
|
|
|
|
setDNSQueryResult(Answer?.map(({ data }) => data) || []),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const [DNSQueryResult, setDNSQueryResult] = createSignal<string[]>([])
|
|
|
|
|
|
|
|
return (
|
2023-09-02 14:02:25 +08:00
|
|
|
<div class="flex flex-col">
|
2023-09-02 18:04:57 +08:00
|
|
|
<form use:form={form} class="flex flex-col gap-2 sm:flex-row">
|
|
|
|
<input
|
|
|
|
name="name"
|
|
|
|
class="input input-bordered w-full max-w-xs sm:flex-1"
|
|
|
|
/>
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
<select name="type" class="select select-bordered">
|
|
|
|
<option>A</option>
|
|
|
|
<option>AAAA</option>
|
|
|
|
<option>MX</option>
|
|
|
|
</select>
|
|
|
|
<button type="submit" class="btn btn-primary">
|
|
|
|
{t('dnsQuery')}
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-09-02 13:54:59 +08:00
|
|
|
</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>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const configFormSchema = z.object({
|
2023-08-28 22:13:48 +08:00
|
|
|
port: z.number(),
|
|
|
|
'socks-port': z.number(),
|
|
|
|
'redir-port': z.number(),
|
|
|
|
'tproxy-port': z.number(),
|
|
|
|
'mixed-port': z.number(),
|
|
|
|
})
|
|
|
|
|
2023-09-02 13:54:59 +08:00
|
|
|
const ConfigForm = () => {
|
2023-08-28 22:13:48 +08:00
|
|
|
const request = useRequest()
|
2023-09-01 14:06:21 +08:00
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2023-09-02 13:54:59 +08:00
|
|
|
const { form, setInitialValues, reset } = createForm<
|
|
|
|
z.infer<typeof configFormSchema>
|
|
|
|
>({ extend: validator({ schema: configFormSchema }) })
|
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-02 13:54:59 +08:00
|
|
|
<form class="contents" use:form={form}>
|
|
|
|
<For each={portsList}>
|
|
|
|
{(item) => (
|
|
|
|
<div class="form-control w-64 max-w-xs">
|
|
|
|
<label class="label">
|
|
|
|
<span class="label-text">{item.label}</span>
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
name={item.key}
|
|
|
|
type="number"
|
|
|
|
class="input input-bordered"
|
|
|
|
placeholder={item.label}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
2023-09-01 14:06:21 +08:00
|
|
|
</form>
|
2023-09-02 13:54:59 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2023-09-01 14:06:21 +08:00
|
|
|
|
2023-09-02 15:08:35 +08:00
|
|
|
const ConfigForXd = () => {
|
2023-09-02 14:25:22 +08:00
|
|
|
const [t] = useI18n()
|
|
|
|
|
2023-09-02 15:08:35 +08:00
|
|
|
return (
|
2023-09-02 19:06:02 +08:00
|
|
|
<div class="grid gap-4">
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<div class="pb-4">{t('autoSwitchTheme')}</div>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class="toggle"
|
|
|
|
checked={autoSwitchTheme()}
|
|
|
|
onChange={(e) => {
|
|
|
|
setAutoSwitchTheme(e.target.checked)
|
|
|
|
applyThemeByMode()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Show when={autoSwitchTheme()}>
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<div class="pb-4">{t('favDayTheme')}</div>
|
|
|
|
<select
|
|
|
|
class="select select-bordered w-full max-w-xs"
|
|
|
|
onChange={(e) => {
|
|
|
|
setFavDayTheme(e.target.value)
|
|
|
|
applyThemeByMode()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<For each={themes}>
|
|
|
|
{(theme) => (
|
|
|
|
<option selected={favDayTheme() === theme} value={theme}>
|
|
|
|
{theme}
|
|
|
|
</option>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<div class="pb-4">{t('favNightTheme')}</div>
|
|
|
|
<select
|
|
|
|
class="select select-bordered w-full max-w-xs"
|
|
|
|
onChange={(e) => {
|
|
|
|
setFavNightTheme(e.target.value)
|
|
|
|
applyThemeByMode()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<For each={themes}>
|
|
|
|
{(theme) => (
|
|
|
|
<option selected={favNightTheme() === theme} value={theme}>
|
|
|
|
{theme}
|
|
|
|
</option>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2023-09-02 15:55:38 +08:00
|
|
|
<div>
|
|
|
|
<div class="pb-4">{t('proxiesPreviewType')}</div>
|
|
|
|
<div class="flex items-center gap-4">
|
|
|
|
<For each={Object.values(PROXIES_PREVIEW_TYPE)}>
|
|
|
|
{(value) => (
|
|
|
|
<label class="flex items-center gap-2">
|
|
|
|
<span>{t(value)}</span>
|
|
|
|
|
|
|
|
<input
|
|
|
|
class="radio"
|
|
|
|
aria-label={value}
|
|
|
|
type="radio"
|
|
|
|
checked={value === proxiesPreviewType()}
|
|
|
|
onChange={() => setProxiesPreviewType(value)}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
2023-09-02 15:08:35 +08:00
|
|
|
</div>
|
2023-09-02 15:55:38 +08:00
|
|
|
|
2023-09-02 15:08:35 +08:00
|
|
|
<div>
|
2023-09-02 15:55:38 +08:00
|
|
|
<div class="pb-4">{t('autoCloseConns')}</div>
|
|
|
|
|
|
|
|
<input
|
|
|
|
class="toggle"
|
|
|
|
type="checkbox"
|
|
|
|
checked={autoCloseConns()}
|
|
|
|
onChange={(e) => setAutoCloseConns(e.target.checked)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
<div class="flex flex-col">
|
2023-09-02 15:55:38 +08:00
|
|
|
<div class="pb-4">{t('urlForDelayTest')}</div>
|
|
|
|
|
2023-09-02 15:08:35 +08:00
|
|
|
<input
|
2023-09-02 19:06:02 +08:00
|
|
|
class="w-100 input input-bordered max-w-md"
|
2023-09-02 15:08:35 +08:00
|
|
|
value={urlForDelayTest()}
|
|
|
|
onChange={(e) => setUrlForDelayTest(e.target?.value!)}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-09-02 15:55:38 +08:00
|
|
|
</div>
|
2023-09-02 15:08:35 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default () => {
|
2023-09-02 13:54:59 +08:00
|
|
|
return (
|
|
|
|
<div class="flex flex-col gap-4">
|
|
|
|
<DNSQueryForm />
|
|
|
|
<ConfigForm />
|
2023-09-02 15:08:35 +08:00
|
|
|
<ConfigForXd />
|
2023-08-28 22:13:48 +08:00
|
|
|
</div>
|
|
|
|
)
|
2023-08-24 04:20:53 +08:00
|
|
|
}
|