Files
frp-panel/www/lib/consts.ts
VaalaCat 373276633f feat: proxy list [新增代理列表实体]
refactor: change client manager structure [重构:更改客户端管理器结构适配影子客户端]

feat: add proxy config table and dao [添加代理配置独立数据表和DAO层]

feat: new proxy config entity [新建的代理配置实体]

feat: update and delete proxy config [更新和删除代理配置接口]

feat: get config api and beautify proxy item [更新获取配置API并美化代理项]

feat: change proxy form style [美化修改代理的表单样式]

fix: client edit [修复:编辑客户端的问题]

fix: shadow copy status error [修复:影子客户端复制状态错误]

fix: http proxy bug [修复:HTTP代理类型的错误]

fix: cannot update client [修复:无法更新客户端]

feat: record trigger refetch [自动重新获取表格内的数据]

fix: filter string length [修复:过滤字符串长度]

fix: add client error [修复:添加客户端错误]

fix: do not notify client when stopped [修复:停止时不通知客户端]

fix: delete when proxy duplicate [修复:代理重复时删除]

feat: add http proxy location [添加HTTP代理路由路径]

chore: edit style [编辑样式美化]

fix: remove expired client [修复:自动移除过期客户端]

feat: proxy status [新增代理状态提示]

fix: build [修复:构建]

fix: refetch trigger [修复:重新获取数据的问题]

fix: remove all expired client [修复:移除所有过期客户端]

feat: i18n for proxy [代理页面的国际化翻译]
2024-12-20 12:18:28 +00:00

81 lines
3.2 KiB
TypeScript

import * as z from 'zod'
import { Client, Server } from './pb/common'
import { GetPlatformInfoResponse } from './pb/api_user'
import { TypedProxyConfig } from '@/types/proxy'
export const API_PATH = '/api/v1'
export const SET_TOKEN_HEADER = 'x-set-authorization'
export const X_CLIENT_REQUEST_ID = 'x-client-request-id'
export const LOCAL_STORAGE_TOKEN_KEY = 'token'
export const ZodPortSchema = z.coerce
.number({ required_error: 'validation.required' })
.min(1, { message: 'validation.portRange.min' })
.max(65535, { message: 'validation.portRange.max' })
export const ZodIPSchema = z.string({ required_error: 'validation.required' })
.regex(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, { message: 'validation.ipAddress' })
export const ZodStringSchema = z.string({ required_error: 'validation.required' })
.min(1, { message: 'validation.required' })
export const ZodEmailSchema = z.string({ required_error: 'validation.required' })
.min(1, { message: 'validation.required' })
.email({ message: 'auth.email.invalid' })
export const TypedProxyConfigValid = (typedProxyCfg: TypedProxyConfig | undefined): boolean => {
return (typedProxyCfg?.localPort && typedProxyCfg.localIP && typedProxyCfg.name && typedProxyCfg.type) ? true : false
}
export const ClientConfigured = (client: Client | undefined): boolean => {
if (client == undefined) {
return false
}
return !((client.config == undefined || client.config == '') &&
(client.clientIds == undefined || client.clientIds.length == 0))
}
// .refine((e) => e === "abcd@fg.com", "This email is not in our database")
export const ExecCommandStr = <T extends Client | Server>(
type: "client" | "server",
item: T,
info: GetPlatformInfoResponse,
fileName?: string,
) => {
return `${fileName || 'frp-panel'} ${type} -s ${item.secret} -i ${item.id} -a ${info.globalSecret} -r ${info.masterRpcHost
} -c ${info.masterRpcPort} -p ${info.masterApiPort} -e ${info.masterApiScheme}`
}
export const WindowsInstallCommand = <T extends Client | Server>(
type: "client" | "server",
item: T,
info: GetPlatformInfoResponse,
) => {
return `[Net.ServicePointManager]::SecurityProtocol = ` +
`[Net.SecurityProtocolType]::Ssl3 -bor ` +
`[Net.SecurityProtocolType]::Tls -bor ` +
`[Net.SecurityProtocolType]::Tls11 -bor ` +
`[Net.SecurityProtocolType]::Tls12;set-ExecutionPolicy RemoteSigned;` +
`Invoke-WebRequest https://raw.githubusercontent.com/VaalaCat/frp-panel/main/install.ps1 ` +
`-OutFile C:\install.ps1;powershell.exe C:\install.ps1 ${ExecCommandStr(type, item, info, ' ')}`
}
export const LinuxInstallCommand = <T extends Client | Server>(
type: "client" | "server",
item: T,
info: GetPlatformInfoResponse,
) => {
return `curl -sSL https://raw.githubusercontent.com/VaalaCat/frp-panel/main/install.sh | bash -s --${ExecCommandStr(type, item, info, ' ')}`
}
export const ClientEnvFile = <T extends Client | Server>(
item: T,
info: GetPlatformInfoResponse,
) => {
return `CLIENT_ID=${item.id}
CLIENT_SECRET=${item.secret}
APP_SECRET=${info.globalSecret}
MASTER_RPC_HOST=${info.masterRpcHost}
MASTER_RPC_PORT=${info.masterRpcPort}
MASTER_API_HOST=${info.masterRpcHost}
MASTER_API_PORT=${info.masterApiPort}
MASTER_API_SCHEME=${info.masterApiScheme}`
}