feat: Add automated ChatGPT account registration with backend API, TLS client, and fingerprinting, alongside new frontend pages for configuration, monitoring, and upload.

This commit is contained in:
2026-02-03 02:39:08 +08:00
parent 389b8eca28
commit 51ba54856d
18 changed files with 1382 additions and 674 deletions

View File

@@ -1,7 +1,7 @@
import { Routes, Route } from 'react-router-dom'
import { ConfigProvider, RecordsProvider } from './context'
import { Layout } from './components/layout'
import { Dashboard, Upload, Records, Accounts, Config, S2AConfig, EmailConfig, Monitor, Cleaner, TeamReg } from './pages'
import { Dashboard, Upload, Records, Accounts, Config, S2AConfig, EmailConfig, Monitor, Cleaner, TeamReg, CodexProxyConfig } from './pages'
function App() {
return (
@@ -19,6 +19,7 @@ function App() {
<Route path="config" element={<Config />} />
<Route path="config/s2a" element={<S2AConfig />} />
<Route path="config/email" element={<EmailConfig />} />
<Route path="config/codex-proxy" element={<CodexProxyConfig />} />
</Route>
</Routes>
</RecordsProvider>

View File

@@ -15,6 +15,7 @@ import {
Cog,
Trash2,
UserPlus,
Globe,
} from 'lucide-react'
interface SidebarProps {
@@ -45,6 +46,7 @@ const navItems: NavItem[] = [
{ to: '/config', icon: Cog, label: '配置概览' },
{ to: '/config/s2a', icon: Server, label: 'S2A 配置' },
{ to: '/config/email', icon: Mail, label: '邮箱配置' },
{ to: '/config/codex-proxy', icon: Globe, label: '代理池' },
]
},
]

View File

@@ -0,0 +1,448 @@
import { useState, useEffect, useCallback } from 'react'
import {
Globe, Plus, Trash2, ToggleLeft, ToggleRight,
Loader2, Save, RefreshCcw, CheckCircle, XCircle,
AlertTriangle, Clock
} from 'lucide-react'
import { Card, CardHeader, CardTitle, CardContent, Button, Input } from '../components/common'
interface CodexProxy {
id: number
proxy_url: string
description: string
is_enabled: boolean
last_used_at: string | null
success_count: number
fail_count: number
created_at: string
}
interface ProxyStats {
total: number
enabled: number
disabled: number
}
export default function CodexProxyConfig() {
const [proxies, setProxies] = useState<CodexProxy[]>([])
const [stats, setStats] = useState<ProxyStats>({ total: 0, enabled: 0, disabled: 0 })
const [loading, setLoading] = useState(true)
const [saving, setSaving] = useState(false)
const [message, setMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null)
// 单个添加
const [newProxyUrl, setNewProxyUrl] = useState('')
const [newDescription, setNewDescription] = useState('')
// 批量添加
const [batchMode, setBatchMode] = useState(false)
const [batchInput, setBatchInput] = useState('')
// 获取代理列表
const fetchProxies = useCallback(async () => {
setLoading(true)
try {
const res = await fetch('/api/codex-proxy')
const data = await res.json()
if (data.code === 0 && data.data) {
setProxies(data.data.proxies || [])
setStats(data.data.stats || { total: 0, enabled: 0, disabled: 0 })
}
} catch (error) {
console.error('获取代理列表失败:', error)
} finally {
setLoading(false)
}
}, [])
useEffect(() => {
fetchProxies()
}, [fetchProxies])
// 添加代理
const handleAddProxy = async () => {
if (!newProxyUrl.trim()) return
setSaving(true)
setMessage(null)
try {
const res = await fetch('/api/codex-proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
proxy_url: newProxyUrl.trim(),
description: newDescription.trim(),
}),
})
const data = await res.json()
if (data.code === 0) {
setMessage({ type: 'success', text: '代理添加成功' })
setNewProxyUrl('')
setNewDescription('')
fetchProxies()
} else {
setMessage({ type: 'error', text: data.message || '添加失败' })
}
} catch {
setMessage({ type: 'error', text: '网络错误' })
} finally {
setSaving(false)
}
}
// 批量添加
const handleBatchAdd = async () => {
const lines = batchInput.split('\n').filter(line => line.trim())
if (lines.length === 0) return
setSaving(true)
setMessage(null)
try {
const res = await fetch('/api/codex-proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ proxies: lines }),
})
const data = await res.json()
if (data.code === 0) {
setMessage({ type: 'success', text: `成功添加 ${data.data.added}/${data.data.total} 个代理` })
setBatchInput('')
fetchProxies()
} else {
setMessage({ type: 'error', text: data.message || '添加失败' })
}
} catch {
setMessage({ type: 'error', text: '网络错误' })
} finally {
setSaving(false)
}
}
// 切换启用状态
const handleToggle = async (id: number) => {
try {
const res = await fetch(`/api/codex-proxy?id=${id}`, { method: 'PUT' })
const data = await res.json()
if (data.code === 0) {
fetchProxies()
}
} catch (error) {
console.error('切换状态失败:', error)
}
}
// 删除代理
const handleDelete = async (id: number) => {
if (!confirm('确定要删除这个代理吗?')) return
try {
const res = await fetch(`/api/codex-proxy?id=${id}`, { method: 'DELETE' })
const data = await res.json()
if (data.code === 0) {
fetchProxies()
}
} catch (error) {
console.error('删除失败:', error)
}
}
// 清空所有
const handleClearAll = async () => {
if (!confirm('确定要清空所有代理吗?此操作不可恢复!')) return
try {
const res = await fetch('/api/codex-proxy?all=true', { method: 'DELETE' })
const data = await res.json()
if (data.code === 0) {
setMessage({ type: 'success', text: '已清空所有代理' })
fetchProxies()
}
} catch (error) {
console.error('清空失败:', error)
}
}
// 格式化代理显示
const formatProxyDisplay = (url: string) => {
if (url.includes('@')) {
const parts = url.split('@')
return parts[parts.length - 1]
}
return url.replace(/^https?:\/\//, '').replace(/^socks5:\/\//, '')
}
// 格式化时间
const formatTime = (timeStr: string | null) => {
if (!timeStr) return '从未'
const date = new Date(timeStr)
return date.toLocaleString('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
}
// 计算成功率
const getSuccessRate = (proxy: CodexProxy) => {
const total = proxy.success_count + proxy.fail_count
if (total === 0) return null
return Math.round((proxy.success_count / total) * 100)
}
if (loading) {
return (
<div className="flex items-center justify-center h-64">
<Loader2 className="h-8 w-8 animate-spin text-blue-500" />
</div>
)
}
return (
<div className="space-y-6">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div>
<h1 className="text-2xl font-bold text-slate-900 dark:text-slate-100 flex items-center gap-2">
<Globe className="h-7 w-7 text-purple-500" />
CodexAuth
</h1>
<p className="text-sm text-slate-500 dark:text-slate-400">
CodexAuth API 使
</p>
</div>
<div className="flex gap-2">
<Button
variant="outline"
onClick={fetchProxies}
icon={<RefreshCcw className="h-4 w-4" />}
>
</Button>
{proxies.length > 0 && (
<Button
variant="danger"
onClick={handleClearAll}
icon={<Trash2 className="h-4 w-4" />}
>
</Button>
)}
</div>
</div>
{/* Message */}
{message && (
<div className={`p-3 rounded-lg text-sm ${message.type === 'success'
? 'bg-green-50 text-green-700 dark:bg-green-900/30 dark:text-green-400'
: 'bg-red-50 text-red-700 dark:bg-red-900/30 dark:text-red-400'
}`}>
{message.text}
</div>
)}
{/* Stats */}
<div className="grid grid-cols-3 gap-4">
<Card>
<CardContent className="py-4">
<div className="text-center">
<div className="text-2xl font-bold text-slate-900 dark:text-slate-100">
{stats.total}
</div>
<div className="text-xs text-slate-500 dark:text-slate-400">
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="py-4">
<div className="text-center">
<div className="text-2xl font-bold text-green-600 dark:text-green-400">
{stats.enabled}
</div>
<div className="text-xs text-slate-500 dark:text-slate-400">
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="py-4">
<div className="text-center">
<div className="text-2xl font-bold text-slate-400">
{stats.disabled}
</div>
<div className="text-xs text-slate-500 dark:text-slate-400">
</div>
</div>
</CardContent>
</Card>
</div>
{/* Add Proxy */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Plus className="h-5 w-5 text-blue-500" />
</CardTitle>
<button
onClick={() => setBatchMode(!batchMode)}
className="text-sm text-blue-600 hover:text-blue-700 dark:text-blue-400"
>
{batchMode ? '单个添加' : '批量添加'}
</button>
</CardHeader>
<CardContent className="space-y-4">
{batchMode ? (
<>
<textarea
value={batchInput}
onChange={(e) => setBatchInput(e.target.value)}
placeholder="每行一个代理地址,格式:&#10;http://user:pass@host:port&#10;http://host:port&#10;socks5://host:port"
rows={6}
className="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg bg-white dark:bg-slate-800 text-slate-900 dark:text-slate-100 placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm font-mono"
/>
<Button
onClick={handleBatchAdd}
disabled={saving || !batchInput.trim()}
icon={saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
>
{saving ? '添加中...' : '批量添加'}
</Button>
</>
) : (
<>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<Input
label="代理地址"
value={newProxyUrl}
onChange={(e) => setNewProxyUrl(e.target.value)}
placeholder="http://user:pass@host:port"
onKeyDown={(e) => e.key === 'Enter' && handleAddProxy()}
/>
<Input
label="备注(可选)"
value={newDescription}
onChange={(e) => setNewDescription(e.target.value)}
placeholder="代理描述"
/>
</div>
<Button
onClick={handleAddProxy}
disabled={saving || !newProxyUrl.trim()}
icon={saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Plus className="h-4 w-4" />}
>
{saving ? '添加中...' : '添加代理'}
</Button>
</>
)}
</CardContent>
</Card>
{/* Proxy List */}
<Card>
<CardHeader>
<CardTitle></CardTitle>
<span className="text-sm text-slate-500">
{proxies.length}
</span>
</CardHeader>
<CardContent>
{proxies.length === 0 ? (
<div className="text-center py-8 text-slate-500 dark:text-slate-400">
<Globe className="h-12 w-12 mx-auto mb-3 opacity-50" />
<p></p>
<p className="text-sm">CodexAuth 使</p>
</div>
) : (
<div className="space-y-3">
{proxies.map((proxy) => {
const successRate = getSuccessRate(proxy)
return (
<div
key={proxy.id}
className={`p-4 rounded-lg border ${proxy.is_enabled
? 'bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700'
: 'bg-slate-50 dark:bg-slate-800/50 border-slate-200 dark:border-slate-700 opacity-60'
}`}
>
<div className="flex items-center justify-between gap-4">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-mono text-sm text-slate-900 dark:text-slate-100 truncate">
{formatProxyDisplay(proxy.proxy_url)}
</span>
{proxy.description && (
<span className="text-xs text-slate-500 dark:text-slate-400">
({proxy.description})
</span>
)}
</div>
<div className="flex items-center gap-4 mt-1 text-xs text-slate-500 dark:text-slate-400">
<span className="flex items-center gap-1">
<Clock className="h-3 w-3" />
{formatTime(proxy.last_used_at)}
</span>
<span className="flex items-center gap-1">
<CheckCircle className="h-3 w-3 text-green-500" />
{proxy.success_count}
</span>
<span className="flex items-center gap-1">
<XCircle className="h-3 w-3 text-red-500" />
{proxy.fail_count}
</span>
{successRate !== null && (
<span className={`flex items-center gap-1 ${successRate >= 80 ? 'text-green-600' : successRate >= 50 ? 'text-yellow-600' : 'text-red-600'
}`}>
<AlertTriangle className="h-3 w-3" />
{successRate}%
</span>
)}
</div>
</div>
<div className="flex items-center gap-2">
<button
onClick={() => handleToggle(proxy.id)}
className="p-1 hover:bg-slate-100 dark:hover:bg-slate-700 rounded"
title={proxy.is_enabled ? '禁用' : '启用'}
>
{proxy.is_enabled ? (
<ToggleRight className="h-6 w-6 text-green-500" />
) : (
<ToggleLeft className="h-6 w-6 text-slate-400" />
)}
</button>
<button
onClick={() => handleDelete(proxy.id)}
className="p-1 hover:bg-red-50 dark:hover:bg-red-900/30 rounded text-red-500"
title="删除"
>
<Trash2 className="h-5 w-5" />
</button>
</div>
</div>
</div>
)
})}
</div>
)}
</CardContent>
</Card>
{/* Info */}
<Card>
<CardContent>
<div className="text-sm text-slate-500 dark:text-slate-400">
<p className="font-medium mb-2">使</p>
<ul className="list-disc list-inside space-y-1">
<li> CodexAuth API 使</li>
<li> HTTP / HTTPS / SOCKS5 </li>
<li><code className="px-1 bg-slate-100 dark:bg-slate-800 rounded">http://user:pass@host:port</code></li>
<li>/</li>
<li>使</li>
</ul>
</div>
</CardContent>
</Card>
</div>
)
}

View File

@@ -357,8 +357,8 @@ export default function Config() {
onClick={() => handleSaveAuthMethod('api')}
disabled={savingAuthMethod}
className={`relative flex flex-col items-center gap-2 p-4 rounded-xl border-2 transition-all duration-200 ${authMethod === 'api'
? 'border-blue-500 bg-gradient-to-br from-blue-50 to-indigo-50 dark:from-blue-900/30 dark:to-indigo-900/30 shadow-sm'
: 'border-slate-200 dark:border-slate-700 hover:border-blue-300 dark:hover:border-blue-800 hover:bg-slate-50 dark:hover:bg-slate-800/50'
? 'border-blue-500 bg-gradient-to-br from-blue-50 to-indigo-50 dark:from-blue-900/30 dark:to-indigo-900/30 shadow-sm'
: 'border-slate-200 dark:border-slate-700 hover:border-blue-300 dark:hover:border-blue-800 hover:bg-slate-50 dark:hover:bg-slate-800/50'
}`}
>
{authMethod === 'api' && (
@@ -367,15 +367,15 @@ export default function Config() {
</div>
)}
<div className={`p-3 rounded-lg ${authMethod === 'api'
? 'bg-blue-500 text-white'
: 'bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400'
? 'bg-blue-500 text-white'
: 'bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400'
}`}>
<Zap className="h-6 w-6" />
</div>
<div className="text-center">
<div className={`font-semibold ${authMethod === 'api'
? 'text-blue-700 dark:text-blue-300'
: 'text-slate-700 dark:text-slate-300'
? 'text-blue-700 dark:text-blue-300'
: 'text-slate-700 dark:text-slate-300'
}`}>
CodexAuth API
</div>
@@ -390,8 +390,8 @@ export default function Config() {
onClick={() => handleSaveAuthMethod('browser')}
disabled={savingAuthMethod}
className={`relative flex flex-col items-center gap-2 p-4 rounded-xl border-2 transition-all duration-200 ${authMethod === 'browser'
? 'border-emerald-500 bg-gradient-to-br from-emerald-50 to-green-50 dark:from-emerald-900/30 dark:to-green-900/30 shadow-sm'
: 'border-slate-200 dark:border-slate-700 hover:border-emerald-300 dark:hover:border-emerald-800 hover:bg-slate-50 dark:hover:bg-slate-800/50'
? 'border-emerald-500 bg-gradient-to-br from-emerald-50 to-green-50 dark:from-emerald-900/30 dark:to-green-900/30 shadow-sm'
: 'border-slate-200 dark:border-slate-700 hover:border-emerald-300 dark:hover:border-emerald-800 hover:bg-slate-50 dark:hover:bg-slate-800/50'
}`}
>
{authMethod === 'browser' && (
@@ -400,20 +400,20 @@ export default function Config() {
</div>
)}
<div className={`p-3 rounded-lg ${authMethod === 'browser'
? 'bg-emerald-500 text-white'
: 'bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400'
? 'bg-emerald-500 text-white'
: 'bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400'
}`}>
<Monitor className="h-6 w-6" />
</div>
<div className="text-center">
<div className={`font-semibold ${authMethod === 'browser'
? 'text-emerald-700 dark:text-emerald-300'
: 'text-slate-700 dark:text-slate-300'
? 'text-emerald-700 dark:text-emerald-300'
: 'text-slate-700 dark:text-slate-300'
}`}>
</div>
<div className="text-xs text-slate-500 dark:text-slate-400 mt-1">
Chromedp/Rod
Chromedp
</div>
</div>
</button>

View File

@@ -70,7 +70,6 @@ export default function Monitor() {
const [pollingInterval, setPollingInterval] = useState(60)
const [replenishUseProxy, setReplenishUseProxy] = useState(false) // 补号时使用代理
const [globalProxy, setGlobalProxy] = useState('') // 全局代理地址(只读显示)
const [browserType, setBrowserType] = useState<'chromedp' | 'rod'>('chromedp') // 授权浏览器引擎
const [authMethod, setAuthMethod] = useState<'api' | 'browser'>('browser') // 授权方式
// 倒计时状态
@@ -135,7 +134,6 @@ export default function Monitor() {
polling_enabled: pollingEnabled,
polling_interval: pollingInterval,
replenish_use_proxy: replenishUseProxy,
browser_type: browserType,
}),
})
const data = await res.json()
@@ -286,7 +284,6 @@ export default function Monitor() {
const pollingEnabledVal = s.polling_enabled || false
const interval = s.polling_interval || 60
const replenishUseProxyVal = s.replenish_use_proxy || false
const browserTypeVal = s.browser_type || 'chromedp'
setTargetInput(target)
setAutoAdd(autoAddVal)
@@ -295,12 +292,11 @@ export default function Monitor() {
setPollingEnabled(pollingEnabledVal)
setPollingInterval(interval)
setReplenishUseProxy(replenishUseProxyVal)
setBrowserType(browserTypeVal as 'chromedp' | 'rod')
savedPollingIntervalRef.current = interval
setCountdown(interval)
// 返回加载的配置用于后续刷新
return { target, autoAdd: autoAddVal, minInterval: minIntervalVal, checkInterval: checkIntervalVal, pollingEnabled: pollingEnabledVal, pollingInterval: interval, replenishUseProxy: replenishUseProxyVal, browserType: browserTypeVal }
return { target, autoAdd: autoAddVal, minInterval: minIntervalVal, checkInterval: checkIntervalVal, pollingEnabled: pollingEnabledVal, pollingInterval: interval, replenishUseProxy: replenishUseProxyVal }
}
}
} catch (e) {
@@ -571,8 +567,8 @@ export default function Monitor() {
<MonitorIcon className="h-5 w-5" />
</div>
<div>
<div className="font-semibold text-emerald-700 dark:text-emerald-300"> ({browserType})</div>
<div className="text-xs text-emerald-600/70 dark:text-emerald-400/70">使</div>
<div className="font-semibold text-emerald-700 dark:text-emerald-300"> (chromedp)</div>
<div className="text-xs text-emerald-600/70 dark:text-emerald-400/70">使</div>
</div>
</>
)}

View File

@@ -72,7 +72,6 @@ export default function Upload() {
const [membersPerTeam, setMembersPerTeam] = useState(4)
const [concurrentTeams, setConcurrentTeams] = useState(2)
const [concurrentS2A, setConcurrentS2A] = useState(2) // 入库并发数
const [browserType] = useState<'chromedp' | 'rod'>('chromedp') // 浏览器引擎类型(只读)
const [useProxy, setUseProxy] = useState(false) // 是否使用全局代理
const [includeOwner, setIncludeOwner] = useState(false) // 母号也入库
const [processCount, setProcessCount] = useState(0) // 处理数量0表示全部
@@ -213,7 +212,7 @@ export default function Upload() {
members_per_team: membersPerTeam,
concurrent_teams: Math.min(concurrentTeams, stats?.valid || 1),
concurrent_s2a: concurrentS2A, // 入库并发数
browser_type: browserType,
browser_type: 'chromedp', // 固定使用 chromedp
headless: true, // 始终使用无头模式
proxy: useProxy ? globalProxy : '',
include_owner: includeOwner, // 母号也入库
@@ -233,7 +232,7 @@ export default function Upload() {
alert('启动失败')
}
setLoading(false)
}, [stats, membersPerTeam, concurrentTeams, concurrentS2A, browserType, useProxy, globalProxy, includeOwner, processCount, fetchStatus])
}, [stats, membersPerTeam, concurrentTeams, concurrentS2A, useProxy, globalProxy, includeOwner, processCount, fetchStatus])
// 停止处理
const handleStop = useCallback(async () => {
@@ -497,7 +496,7 @@ export default function Upload() {
<Monitor className="h-4 w-4" />
</div>
<div>
<div className="font-medium text-emerald-700 dark:text-emerald-300"> ({browserType})</div>
<div className="font-medium text-emerald-700 dark:text-emerald-300"> (chromedp)</div>
<div className="text-xs text-emerald-600/70 dark:text-emerald-400/70">使</div>
</div>
</>

View File

@@ -8,5 +8,6 @@ export { default as EmailConfig } from './EmailConfig'
export { default as Monitor } from './Monitor'
export { default as Cleaner } from './Cleaner'
export { default as TeamReg } from './TeamReg'
export { default as CodexProxyConfig } from './CodexProxyConfig'