| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364 |
- /*
- Copyright (C) 2025 QuantumNous
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
- For commercial licensing, please contact support@quantumnous.com
- */
- import React, { useEffect, useState, useRef } from 'react';
- import {
- Button,
- Form,
- Row,
- Col,
- Typography,
- Modal,
- Banner,
- TagInput,
- Spin,
- Card,
- Radio,
- } from '@douyinfe/semi-ui';
- const { Text } = Typography;
- import {
- API,
- removeTrailingSlash,
- showError,
- showSuccess,
- toBoolean,
- } from '../../helpers';
- import axios from 'axios';
- import { useTranslation } from 'react-i18next';
- const SystemSetting = () => {
- const { t } = useTranslation();
- let [inputs, setInputs] = useState({
-
- PasswordLoginEnabled: '',
- PasswordRegisterEnabled: '',
- EmailVerificationEnabled: '',
- GitHubOAuthEnabled: '',
- GitHubClientId: '',
- GitHubClientSecret: '',
- 'oidc.enabled': '',
- 'oidc.client_id': '',
- 'oidc.client_secret': '',
- 'oidc.well_known': '',
- 'oidc.authorization_endpoint': '',
- 'oidc.token_endpoint': '',
- 'oidc.user_info_endpoint': '',
- Notice: '',
- SMTPServer: '',
- SMTPPort: '',
- SMTPAccount: '',
- SMTPFrom: '',
- SMTPToken: '',
- WorkerUrl: '',
- WorkerValidKey: '',
- WorkerAllowHttpImageRequestEnabled: '',
- Footer: '',
- WeChatAuthEnabled: '',
- WeChatServerAddress: '',
- WeChatServerToken: '',
- WeChatAccountQRCodeImageURL: '',
- TurnstileCheckEnabled: '',
- TurnstileSiteKey: '',
- TurnstileSecretKey: '',
- RegisterEnabled: '',
- EmailDomainRestrictionEnabled: '',
- EmailAliasRestrictionEnabled: '',
- SMTPSSLEnabled: '',
- EmailDomainWhitelist: [],
- TelegramOAuthEnabled: '',
- TelegramBotToken: '',
- TelegramBotName: '',
- LinuxDOOAuthEnabled: '',
- LinuxDOClientId: '',
- LinuxDOClientSecret: '',
- LinuxDOMinimumTrustLevel: '',
- ServerAddress: '',
- // SSRF防护配置
- 'fetch_setting.enable_ssrf_protection': true,
- 'fetch_setting.allow_private_ip': '',
- 'fetch_setting.domain_filter_mode': false, // true 白名单,false 黑名单
- 'fetch_setting.ip_filter_mode': false, // true 白名单,false 黑名单
- 'fetch_setting.domain_list': [],
- 'fetch_setting.ip_list': [],
- 'fetch_setting.allowed_ports': [],
- 'fetch_setting.apply_ip_filter_for_domain': false,
- });
- const [originInputs, setOriginInputs] = useState({});
- const [loading, setLoading] = useState(false);
- const [isLoaded, setIsLoaded] = useState(false);
- const formApiRef = useRef(null);
- const [emailDomainWhitelist, setEmailDomainWhitelist] = useState([]);
- const [showPasswordLoginConfirmModal, setShowPasswordLoginConfirmModal] =
- useState(false);
- const [linuxDOOAuthEnabled, setLinuxDOOAuthEnabled] = useState(false);
- const [emailToAdd, setEmailToAdd] = useState('');
- const [domainFilterMode, setDomainFilterMode] = useState(true);
- const [ipFilterMode, setIpFilterMode] = useState(true);
- const [domainList, setDomainList] = useState([]);
- const [ipList, setIpList] = useState([]);
- const [allowedPorts, setAllowedPorts] = useState([]);
- const getOptions = async () => {
- setLoading(true);
- const res = await API.get('/api/option/');
- const { success, message, data } = res.data;
- if (success) {
- let newInputs = {};
- data.forEach((item) => {
- switch (item.key) {
- case 'TopupGroupRatio':
- item.value = JSON.stringify(JSON.parse(item.value), null, 2);
- break;
- case 'EmailDomainWhitelist':
- setEmailDomainWhitelist(item.value ? item.value.split(',') : []);
- break;
- case 'fetch_setting.allow_private_ip':
- case 'fetch_setting.enable_ssrf_protection':
- case 'fetch_setting.domain_filter_mode':
- case 'fetch_setting.ip_filter_mode':
- case 'fetch_setting.apply_ip_filter_for_domain':
- item.value = toBoolean(item.value);
- break;
- case 'fetch_setting.domain_list':
- try {
- const domains = item.value ? JSON.parse(item.value) : [];
- setDomainList(Array.isArray(domains) ? domains : []);
- } catch (e) {
- setDomainList([]);
- }
- break;
- case 'fetch_setting.ip_list':
- try {
- const ips = item.value ? JSON.parse(item.value) : [];
- setIpList(Array.isArray(ips) ? ips : []);
- } catch (e) {
- setIpList([]);
- }
- break;
- case 'fetch_setting.allowed_ports':
- try {
- const ports = item.value ? JSON.parse(item.value) : [];
- setAllowedPorts(Array.isArray(ports) ? ports : []);
- } catch (e) {
- setAllowedPorts(['80', '443', '8080', '8443']);
- }
- break;
- case 'PasswordLoginEnabled':
- case 'PasswordRegisterEnabled':
- case 'EmailVerificationEnabled':
- case 'GitHubOAuthEnabled':
- case 'WeChatAuthEnabled':
- case 'TelegramOAuthEnabled':
- case 'RegisterEnabled':
- case 'TurnstileCheckEnabled':
- case 'EmailDomainRestrictionEnabled':
- case 'EmailAliasRestrictionEnabled':
- case 'SMTPSSLEnabled':
- case 'LinuxDOOAuthEnabled':
- case 'oidc.enabled':
- case 'WorkerAllowHttpImageRequestEnabled':
- item.value = toBoolean(item.value);
- break;
- case 'Price':
- case 'MinTopUp':
- item.value = parseFloat(item.value);
- break;
- default:
- break;
- }
- newInputs[item.key] = item.value;
- });
- setInputs(newInputs);
- setOriginInputs(newInputs);
- // 同步模式布尔到本地状态
- if (typeof newInputs['fetch_setting.domain_filter_mode'] !== 'undefined') {
- setDomainFilterMode(!!newInputs['fetch_setting.domain_filter_mode']);
- }
- if (typeof newInputs['fetch_setting.ip_filter_mode'] !== 'undefined') {
- setIpFilterMode(!!newInputs['fetch_setting.ip_filter_mode']);
- }
- if (formApiRef.current) {
- formApiRef.current.setValues(newInputs);
- }
- setIsLoaded(true);
- } else {
- showError(message);
- }
- setLoading(false);
- };
- useEffect(() => {
- getOptions();
- }, []);
- const updateOptions = async (options) => {
- setLoading(true);
- try {
- // 分离 checkbox 类型的选项和其他选项
- const checkboxOptions = options.filter((opt) =>
- opt.key.toLowerCase().endsWith('enabled'),
- );
- const otherOptions = options.filter(
- (opt) => !opt.key.toLowerCase().endsWith('enabled'),
- );
- // 处理 checkbox 类型的选项
- for (const opt of checkboxOptions) {
- const res = await API.put('/api/option/', {
- key: opt.key,
- value: opt.value.toString(),
- });
- if (!res.data.success) {
- showError(res.data.message);
- return;
- }
- }
- // 处理其他选项
- if (otherOptions.length > 0) {
- const requestQueue = otherOptions.map((opt) =>
- API.put('/api/option/', {
- key: opt.key,
- value:
- typeof opt.value === 'boolean' ? opt.value.toString() : opt.value,
- }),
- );
- const results = await Promise.all(requestQueue);
- // 检查所有请求是否成功
- const errorResults = results.filter((res) => !res.data.success);
- errorResults.forEach((res) => {
- showError(res.data.message);
- });
- }
- showSuccess(t('更新成功'));
- // 更新本地状态
- const newInputs = { ...inputs };
- options.forEach((opt) => {
- newInputs[opt.key] = opt.value;
- });
- setInputs(newInputs);
- } catch (error) {
- showError(t('更新失败'));
- }
- setLoading(false);
- };
- const handleFormChange = (values) => {
- setInputs(values);
- };
- const submitWorker = async () => {
- let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
- const options = [
- { key: 'WorkerUrl', value: WorkerUrl },
- {
- key: 'WorkerAllowHttpImageRequestEnabled',
- value: inputs.WorkerAllowHttpImageRequestEnabled ? 'true' : 'false',
- },
- ];
- if (inputs.WorkerValidKey !== '' || WorkerUrl === '') {
- options.push({ key: 'WorkerValidKey', value: inputs.WorkerValidKey });
- }
- await updateOptions(options);
- };
- const submitServerAddress = async () => {
- let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
- await updateOptions([{ key: 'ServerAddress', value: ServerAddress }]);
- };
- const submitSMTP = async () => {
- const options = [];
- if (originInputs['SMTPServer'] !== inputs.SMTPServer) {
- options.push({ key: 'SMTPServer', value: inputs.SMTPServer });
- }
- if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
- options.push({ key: 'SMTPAccount', value: inputs.SMTPAccount });
- }
- if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) {
- options.push({ key: 'SMTPFrom', value: inputs.SMTPFrom });
- }
- if (
- originInputs['SMTPPort'] !== inputs.SMTPPort &&
- inputs.SMTPPort !== ''
- ) {
- options.push({ key: 'SMTPPort', value: inputs.SMTPPort });
- }
- if (
- originInputs['SMTPToken'] !== inputs.SMTPToken &&
- inputs.SMTPToken !== ''
- ) {
- options.push({ key: 'SMTPToken', value: inputs.SMTPToken });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const submitEmailDomainWhitelist = async () => {
- if (Array.isArray(emailDomainWhitelist)) {
- await updateOptions([
- {
- key: 'EmailDomainWhitelist',
- value: emailDomainWhitelist.join(','),
- },
- ]);
- } else {
- showError(t('邮箱域名白名单格式不正确'));
- }
- };
- const submitSSRF = async () => {
- const options = [];
- // 处理域名过滤模式与列表
- options.push({
- key: 'fetch_setting.domain_filter_mode',
- value: domainFilterMode,
- });
- if (Array.isArray(domainList)) {
- options.push({
- key: 'fetch_setting.domain_list',
- value: JSON.stringify(domainList),
- });
- }
- // 处理IP过滤模式与列表
- options.push({
- key: 'fetch_setting.ip_filter_mode',
- value: ipFilterMode,
- });
- if (Array.isArray(ipList)) {
- options.push({
- key: 'fetch_setting.ip_list',
- value: JSON.stringify(ipList),
- });
- }
- // 处理端口配置
- if (Array.isArray(allowedPorts)) {
- options.push({
- key: 'fetch_setting.allowed_ports',
- value: JSON.stringify(allowedPorts),
- });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const handleAddEmail = () => {
- if (emailToAdd && emailToAdd.trim() !== '') {
- const domain = emailToAdd.trim();
- // 验证域名格式
- const domainRegex =
- /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
- if (!domainRegex.test(domain)) {
- showError(t('邮箱域名格式不正确,请输入有效的域名,如 gmail.com'));
- return;
- }
- // 检查是否已存在
- if (emailDomainWhitelist.includes(domain)) {
- showError(t('该域名已存在于白名单中'));
- return;
- }
- setEmailDomainWhitelist([...emailDomainWhitelist, domain]);
- setEmailToAdd('');
- showSuccess(t('已添加到白名单'));
- }
- };
- const submitWeChat = async () => {
- const options = [];
- if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
- options.push({
- key: 'WeChatServerAddress',
- value: removeTrailingSlash(inputs.WeChatServerAddress),
- });
- }
- if (
- originInputs['WeChatAccountQRCodeImageURL'] !==
- inputs.WeChatAccountQRCodeImageURL
- ) {
- options.push({
- key: 'WeChatAccountQRCodeImageURL',
- value: inputs.WeChatAccountQRCodeImageURL,
- });
- }
- if (
- originInputs['WeChatServerToken'] !== inputs.WeChatServerToken &&
- inputs.WeChatServerToken !== ''
- ) {
- options.push({
- key: 'WeChatServerToken',
- value: inputs.WeChatServerToken,
- });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const submitGitHubOAuth = async () => {
- const options = [];
- if (originInputs['GitHubClientId'] !== inputs.GitHubClientId) {
- options.push({ key: 'GitHubClientId', value: inputs.GitHubClientId });
- }
- if (
- originInputs['GitHubClientSecret'] !== inputs.GitHubClientSecret &&
- inputs.GitHubClientSecret !== ''
- ) {
- options.push({
- key: 'GitHubClientSecret',
- value: inputs.GitHubClientSecret,
- });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const submitOIDCSettings = async () => {
- if (inputs['oidc.well_known'] && inputs['oidc.well_known'] !== '') {
- if (
- !inputs['oidc.well_known'].startsWith('http://') &&
- !inputs['oidc.well_known'].startsWith('https://')
- ) {
- showError(t('Well-Known URL 必须以 http:// 或 https:// 开头'));
- return;
- }
- try {
- const res = await axios.create().get(inputs['oidc.well_known']);
- inputs['oidc.authorization_endpoint'] =
- res.data['authorization_endpoint'];
- inputs['oidc.token_endpoint'] = res.data['token_endpoint'];
- inputs['oidc.user_info_endpoint'] = res.data['userinfo_endpoint'];
- showSuccess(t('获取 OIDC 配置成功!'));
- } catch (err) {
- console.error(err);
- showError(
- t('获取 OIDC 配置失败,请检查网络状况和 Well-Known URL 是否正确'),
- );
- return;
- }
- }
- const options = [];
- if (originInputs['oidc.well_known'] !== inputs['oidc.well_known']) {
- options.push({
- key: 'oidc.well_known',
- value: inputs['oidc.well_known'],
- });
- }
- if (originInputs['oidc.client_id'] !== inputs['oidc.client_id']) {
- options.push({ key: 'oidc.client_id', value: inputs['oidc.client_id'] });
- }
- if (
- originInputs['oidc.client_secret'] !== inputs['oidc.client_secret'] &&
- inputs['oidc.client_secret'] !== ''
- ) {
- options.push({
- key: 'oidc.client_secret',
- value: inputs['oidc.client_secret'],
- });
- }
- if (
- originInputs['oidc.authorization_endpoint'] !==
- inputs['oidc.authorization_endpoint']
- ) {
- options.push({
- key: 'oidc.authorization_endpoint',
- value: inputs['oidc.authorization_endpoint'],
- });
- }
- if (originInputs['oidc.token_endpoint'] !== inputs['oidc.token_endpoint']) {
- options.push({
- key: 'oidc.token_endpoint',
- value: inputs['oidc.token_endpoint'],
- });
- }
- if (
- originInputs['oidc.user_info_endpoint'] !==
- inputs['oidc.user_info_endpoint']
- ) {
- options.push({
- key: 'oidc.user_info_endpoint',
- value: inputs['oidc.user_info_endpoint'],
- });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const submitTelegramSettings = async () => {
- const options = [
- { key: 'TelegramBotToken', value: inputs.TelegramBotToken },
- { key: 'TelegramBotName', value: inputs.TelegramBotName },
- ];
- await updateOptions(options);
- };
- const submitTurnstile = async () => {
- const options = [];
- if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
- options.push({ key: 'TurnstileSiteKey', value: inputs.TurnstileSiteKey });
- }
- if (
- originInputs['TurnstileSecretKey'] !== inputs.TurnstileSecretKey &&
- inputs.TurnstileSecretKey !== ''
- ) {
- options.push({
- key: 'TurnstileSecretKey',
- value: inputs.TurnstileSecretKey,
- });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const submitLinuxDOOAuth = async () => {
- const options = [];
- if (originInputs['LinuxDOClientId'] !== inputs.LinuxDOClientId) {
- options.push({ key: 'LinuxDOClientId', value: inputs.LinuxDOClientId });
- }
- if (
- originInputs['LinuxDOClientSecret'] !== inputs.LinuxDOClientSecret &&
- inputs.LinuxDOClientSecret !== ''
- ) {
- options.push({
- key: 'LinuxDOClientSecret',
- value: inputs.LinuxDOClientSecret,
- });
- }
- if (
- originInputs['LinuxDOMinimumTrustLevel'] !==
- inputs.LinuxDOMinimumTrustLevel
- ) {
- options.push({
- key: 'LinuxDOMinimumTrustLevel',
- value: inputs.LinuxDOMinimumTrustLevel,
- });
- }
- if (options.length > 0) {
- await updateOptions(options);
- }
- };
- const handleCheckboxChange = async (optionKey, event) => {
- const value = event.target.checked;
- if (optionKey === 'PasswordLoginEnabled' && !value) {
- setShowPasswordLoginConfirmModal(true);
- } else {
- await updateOptions([{ key: optionKey, value }]);
- }
- if (optionKey === 'LinuxDOOAuthEnabled') {
- setLinuxDOOAuthEnabled(value);
- }
- };
- const handlePasswordLoginConfirm = async () => {
- await updateOptions([{ key: 'PasswordLoginEnabled', value: false }]);
- setShowPasswordLoginConfirmModal(false);
- };
- return (
- <div>
- {isLoaded ? (
- <Form
- initValues={inputs}
- onValueChange={handleFormChange}
- getFormApi={(api) => (formApiRef.current = api)}
- >
- {({ formState, values, formApi }) => (
- <div
- style={{
- display: 'flex',
- flexDirection: 'column',
- gap: '10px',
- marginTop: '10px',
- }}
- >
- <Card>
- <Form.Section text={t('通用设置')}>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={24} lg={24} xl={24}>
- <Form.Input
- field='ServerAddress'
- label={t('服务器地址')}
- placeholder='https://yourdomain.com'
- extraText={t(
- '该服务器地址将影响支付回调地址以及默认首页展示的地址,请确保正确配置',
- )}
- />
- </Col>
- </Row>
- <Button onClick={submitServerAddress}>
- {t('更新服务器地址')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('代理设置')}>
- <Text>
- (支持{' '}
- <a
- href='https://github.com/Calcium-Ion/new-api-worker'
- target='_blank'
- rel='noreferrer'
- >
- new-api-worker
- </a>
- )
- </Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='WorkerUrl'
- label={t('Worker地址')}
- placeholder='例如:https://workername.yourdomain.workers.dev'
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='WorkerValidKey'
- label={t('Worker密钥')}
- placeholder='敏感信息不会发送到前端显示'
- type='password'
- />
- </Col>
- </Row>
- <Form.Checkbox
- field='WorkerAllowHttpImageRequestEnabled'
- noLabel
- >
- {t('允许 HTTP 协议图片请求(适用于自部署代理)')}
- </Form.Checkbox>
- <Button onClick={submitWorker}>{t('更新Worker设置')}</Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('SSRF防护设置')}>
- <Text extraText={t('SSRF防护详细说明')}>
- {t('配置服务器端请求伪造(SSRF)防护,用于保护内网资源安全')}
- </Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={24} lg={24} xl={24}>
- <Form.Checkbox
- field='fetch_setting.enable_ssrf_protection'
- noLabel
- extraText={t('SSRF防护开关详细说明')}
- onChange={(e) =>
- handleCheckboxChange('fetch_setting.enable_ssrf_protection', e)
- }
- >
- {t('启用SSRF防护(推荐开启以保护服务器安全)')}
- </Form.Checkbox>
- </Col>
- </Row>
-
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- style={{ marginTop: 16 }}
- >
- <Col xs={24} sm={24} md={24} lg={24} xl={24}>
- <Form.Checkbox
- field='fetch_setting.allow_private_ip'
- noLabel
- extraText={t('私有IP访问详细说明')}
- onChange={(e) =>
- handleCheckboxChange('fetch_setting.allow_private_ip', e)
- }
- >
- {t('允许访问私有IP地址(127.0.0.1、192.168.x.x等内网地址)')}
- </Form.Checkbox>
- </Col>
- </Row>
-
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- style={{ marginTop: 16 }}
- >
- <Col xs={24} sm={24} md={24} lg={24} xl={24}>
- <Form.Checkbox
- field='fetch_setting.apply_ip_filter_for_domain'
- noLabel
- extraText={t('域名IP过滤详细说明')}
- onChange={(e) =>
- handleCheckboxChange('fetch_setting.apply_ip_filter_for_domain', e)
- }
- style={{ marginBottom: 8 }}
- >
- {t('对域名启用 IP 过滤(实验性)')}
- </Form.Checkbox>
- <Text strong>
- {t(domainFilterMode ? '域名白名单' : '域名黑名单')}
- </Text>
- <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
- {t('支持通配符格式,如:example.com, *.api.example.com')}
- </Text>
- <Radio.Group
- type='button'
- value={domainFilterMode ? 'whitelist' : 'blacklist'}
- onChange={(val) => {
- const selected = val && val.target ? val.target.value : val;
- const isWhitelist = selected === 'whitelist';
- setDomainFilterMode(isWhitelist);
- setInputs(prev => ({
- ...prev,
- 'fetch_setting.domain_filter_mode': isWhitelist,
- }));
- }}
- style={{ marginBottom: 8 }}
- >
- <Radio value='whitelist'>{t('白名单')}</Radio>
- <Radio value='blacklist'>{t('黑名单')}</Radio>
- </Radio.Group>
- <TagInput
- value={domainList}
- onChange={(value) => {
- setDomainList(value);
- // 触发Form的onChange事件
- setInputs(prev => ({
- ...prev,
- 'fetch_setting.domain_list': value
- }));
- }}
- placeholder={t('输入域名后回车,如:example.com')}
- style={{ width: '100%' }}
- />
- </Col>
- </Row>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- style={{ marginTop: 16 }}
- >
- <Col xs={24} sm={24} md={24} lg={24} xl={24}>
- <Text strong>
- {t(ipFilterMode ? 'IP白名单' : 'IP黑名单')}
- </Text>
- <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
- {t('支持CIDR格式,如:8.8.8.8, 192.168.1.0/24')}
- </Text>
- <Radio.Group
- type='button'
- value={ipFilterMode ? 'whitelist' : 'blacklist'}
- onChange={(val) => {
- const selected = val && val.target ? val.target.value : val;
- const isWhitelist = selected === 'whitelist';
- setIpFilterMode(isWhitelist);
- setInputs(prev => ({
- ...prev,
- 'fetch_setting.ip_filter_mode': isWhitelist,
- }));
- }}
- style={{ marginBottom: 8 }}
- >
- <Radio value='whitelist'>{t('白名单')}</Radio>
- <Radio value='blacklist'>{t('黑名单')}</Radio>
- </Radio.Group>
- <TagInput
- value={ipList}
- onChange={(value) => {
- setIpList(value);
- // 触发Form的onChange事件
- setInputs(prev => ({
- ...prev,
- 'fetch_setting.ip_list': value
- }));
- }}
- placeholder={t('输入IP地址后回车,如:8.8.8.8')}
- style={{ width: '100%' }}
- />
- </Col>
- </Row>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- style={{ marginTop: 16 }}
- >
- <Col xs={24} sm={24} md={24} lg={24} xl={24}>
- <Text strong>{t('允许的端口')}</Text>
- <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
- {t('支持单个端口和端口范围,如:80, 443, 8000-8999')}
- </Text>
- <TagInput
- value={allowedPorts}
- onChange={(value) => {
- setAllowedPorts(value);
- // 触发Form的onChange事件
- setInputs(prev => ({
- ...prev,
- 'fetch_setting.allowed_ports': value
- }));
- }}
- placeholder={t('输入端口后回车,如:80 或 8000-8999')}
- style={{ width: '100%' }}
- />
- <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
- {t('端口配置详细说明')}
- </Text>
- </Col>
- </Row>
- <Button onClick={submitSSRF} style={{ marginTop: 16 }}>
- {t('更新SSRF防护设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置登录注册')}>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Checkbox
- field='PasswordLoginEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('PasswordLoginEnabled', e)
- }
- >
- {t('允许通过密码进行登录')}
- </Form.Checkbox>
- <Form.Checkbox
- field='PasswordRegisterEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('PasswordRegisterEnabled', e)
- }
- >
- {t('允许通过密码进行注册')}
- </Form.Checkbox>
- <Form.Checkbox
- field='EmailVerificationEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('EmailVerificationEnabled', e)
- }
- >
- {t('通过密码注册时需要进行邮箱验证')}
- </Form.Checkbox>
- <Form.Checkbox
- field='RegisterEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('RegisterEnabled', e)
- }
- >
- {t('允许新用户注册')}
- </Form.Checkbox>
- <Form.Checkbox
- field='TurnstileCheckEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('TurnstileCheckEnabled', e)
- }
- >
- {t('允许 Turnstile 用户校验')}
- </Form.Checkbox>
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Checkbox
- field='GitHubOAuthEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('GitHubOAuthEnabled', e)
- }
- >
- {t('允许通过 GitHub 账户登录 & 注册')}
- </Form.Checkbox>
- <Form.Checkbox
- field='LinuxDOOAuthEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('LinuxDOOAuthEnabled', e)
- }
- >
- {t('允许通过 Linux DO 账户登录 & 注册')}
- </Form.Checkbox>
- <Form.Checkbox
- field='WeChatAuthEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('WeChatAuthEnabled', e)
- }
- >
- {t('允许通过微信登录 & 注册')}
- </Form.Checkbox>
- <Form.Checkbox
- field='TelegramOAuthEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('TelegramOAuthEnabled', e)
- }
- >
- {t('允许通过 Telegram 进行登录')}
- </Form.Checkbox>
- <Form.Checkbox
- field="['oidc.enabled']"
- noLabel
- onChange={(e) =>
- handleCheckboxChange('oidc.enabled', e)
- }
- >
- {t('允许通过 OIDC 进行登录')}
- </Form.Checkbox>
- </Col>
- </Row>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置邮箱域名白名单')}>
- <Text>{t('用以防止恶意用户利用临时邮箱批量注册')}</Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Checkbox
- field='EmailDomainRestrictionEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange(
- 'EmailDomainRestrictionEnabled',
- e,
- )
- }
- >
- 启用邮箱域名白名单
- </Form.Checkbox>
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Checkbox
- field='EmailAliasRestrictionEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange(
- 'EmailAliasRestrictionEnabled',
- e,
- )
- }
- >
- 启用邮箱别名限制
- </Form.Checkbox>
- </Col>
- </Row>
- <TagInput
- value={emailDomainWhitelist}
- onChange={setEmailDomainWhitelist}
- placeholder={t('输入域名后回车')}
- style={{ width: '100%', marginTop: 16 }}
- />
- <Form.Input
- placeholder={t('输入要添加的邮箱域名')}
- value={emailToAdd}
- onChange={(value) => setEmailToAdd(value)}
- style={{ marginTop: 16 }}
- suffix={
- <Button
- theme='solid'
- type='primary'
- onClick={handleAddEmail}
- >
- {t('添加')}
- </Button>
- }
- onEnterPress={handleAddEmail}
- />
- <Button
- onClick={submitEmailDomainWhitelist}
- style={{ marginTop: 10 }}
- >
- {t('保存邮箱域名白名单设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 SMTP')}>
- <Text>{t('用以支持系统的邮件发送')}</Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input
- field='SMTPServer'
- label={t('SMTP 服务器地址')}
- />
- </Col>
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input field='SMTPPort' label={t('SMTP 端口')} />
- </Col>
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input field='SMTPAccount' label={t('SMTP 账户')} />
- </Col>
- </Row>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- style={{ marginTop: 16 }}
- >
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input
- field='SMTPFrom'
- label={t('SMTP 发送者邮箱')}
- />
- </Col>
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input
- field='SMTPToken'
- label={t('SMTP 访问凭证')}
- type='password'
- placeholder='敏感信息不会发送到前端显示'
- />
- </Col>
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Checkbox
- field='SMTPSSLEnabled'
- noLabel
- onChange={(e) =>
- handleCheckboxChange('SMTPSSLEnabled', e)
- }
- >
- {t('启用SMTP SSL')}
- </Form.Checkbox>
- </Col>
- </Row>
- <Button onClick={submitSMTP}>{t('保存 SMTP 设置')}</Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 OIDC')}>
- <Text>
- {t(
- '用以支持通过 OIDC 登录,例如 Okta、Auth0 等兼容 OIDC 协议的 IdP',
- )}
- </Text>
- <Banner
- type='info'
- description={`${t('主页链接填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')},${t('重定向 URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')}/oauth/oidc`}
- style={{ marginBottom: 20, marginTop: 16 }}
- />
- <Text>
- {t(
- '若你的 OIDC Provider 支持 Discovery Endpoint,你可以仅填写 OIDC Well-Known URL,系统会自动获取 OIDC 配置',
- )}
- </Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field="['oidc.well_known']"
- label={t('Well-Known URL')}
- placeholder={t('请输入 OIDC 的 Well-Known URL')}
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field="['oidc.client_id']"
- label={t('Client ID')}
- placeholder={t('输入 OIDC 的 Client ID')}
- />
- </Col>
- </Row>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field="['oidc.client_secret']"
- label={t('Client Secret')}
- type='password'
- placeholder={t('敏感信息不会发送到前端显示')}
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field="['oidc.authorization_endpoint']"
- label={t('Authorization Endpoint')}
- placeholder={t('输入 OIDC 的 Authorization Endpoint')}
- />
- </Col>
- </Row>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field="['oidc.token_endpoint']"
- label={t('Token Endpoint')}
- placeholder={t('输入 OIDC 的 Token Endpoint')}
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field="['oidc.user_info_endpoint']"
- label={t('User Info Endpoint')}
- placeholder={t('输入 OIDC 的 Userinfo Endpoint')}
- />
- </Col>
- </Row>
- <Button onClick={submitOIDCSettings}>
- {t('保存 OIDC 设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 GitHub OAuth App')}>
- <Text>{t('用以支持通过 GitHub 进行登录注册')}</Text>
- <Banner
- type='info'
- description={`${t('Homepage URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')},${t('Authorization callback URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')}/oauth/github`}
- style={{ marginBottom: 20, marginTop: 16 }}
- />
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='GitHubClientId'
- label={t('GitHub Client ID')}
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='GitHubClientSecret'
- label={t('GitHub Client Secret')}
- type='password'
- placeholder={t('敏感信息不会发送到前端显示')}
- />
- </Col>
- </Row>
- <Button onClick={submitGitHubOAuth}>
- {t('保存 GitHub OAuth 设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 Linux DO OAuth')}>
- <Text>
- {t('用以支持通过 Linux DO 进行登录注册')}
- <a
- href='https://connect.linux.do/'
- target='_blank'
- rel='noreferrer'
- style={{
- display: 'inline-block',
- marginLeft: 4,
- marginRight: 4,
- }}
- >
- {t('点击此处')}
- </a>
- {t('管理你的 LinuxDO OAuth App')}
- </Text>
- <Banner
- type='info'
- description={`${t('回调 URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')}/oauth/linuxdo`}
- style={{ marginBottom: 20, marginTop: 16 }}
- />
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={10} lg={10} xl={10}>
- <Form.Input
- field='LinuxDOClientId'
- label={t('Linux DO Client ID')}
- placeholder={t('输入你注册的 LinuxDO OAuth APP 的 ID')}
- />
- </Col>
- <Col xs={24} sm={24} md={10} lg={10} xl={10}>
- <Form.Input
- field='LinuxDOClientSecret'
- label={t('Linux DO Client Secret')}
- type='password'
- placeholder={t('敏感信息不会发送到前端显示')}
- />
- </Col>
- <Col xs={24} sm={24} md={4} lg={4} xl={4}>
- <Form.Input
- field='LinuxDOMinimumTrustLevel'
- label='LinuxDO Minimum Trust Level'
- placeholder='允许注册的最低信任等级'
- />
- </Col>
- </Row>
- <Button onClick={submitLinuxDOOAuth}>
- {t('保存 Linux DO OAuth 设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 WeChat Server')}>
- <Text>{t('用以支持通过微信进行登录注册')}</Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input
- field='WeChatServerAddress'
- label={t('WeChat Server 服务器地址')}
- />
- </Col>
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input
- field='WeChatServerToken'
- label={t('WeChat Server 访问凭证')}
- type='password'
- placeholder={t('敏感信息不会发送到前端显示')}
- />
- </Col>
- <Col xs={24} sm={24} md={8} lg={8} xl={8}>
- <Form.Input
- field='WeChatAccountQRCodeImageURL'
- label={t('微信公众号二维码图片链接')}
- />
- </Col>
- </Row>
- <Button onClick={submitWeChat}>
- {t('保存 WeChat Server 设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 Telegram 登录')}>
- <Text>{t('用以支持通过 Telegram 进行登录注册')}</Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='TelegramBotToken'
- label={t('Telegram Bot Token')}
- placeholder={t('敏感信息不会发送到前端显示')}
- type='password'
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='TelegramBotName'
- label={t('Telegram Bot 名称')}
- />
- </Col>
- </Row>
- <Button onClick={submitTelegramSettings}>
- {t('保存 Telegram 登录设置')}
- </Button>
- </Form.Section>
- </Card>
- <Card>
- <Form.Section text={t('配置 Turnstile')}>
- <Text>{t('用以支持用户校验')}</Text>
- <Row
- gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
- >
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='TurnstileSiteKey'
- label={t('Turnstile Site Key')}
- />
- </Col>
- <Col xs={24} sm={24} md={12} lg={12} xl={12}>
- <Form.Input
- field='TurnstileSecretKey'
- label={t('Turnstile Secret Key')}
- type='password'
- placeholder={t('敏感信息不会发送到前端显示')}
- />
- </Col>
- </Row>
- <Button onClick={submitTurnstile}>
- {t('保存 Turnstile 设置')}
- </Button>
- </Form.Section>
- </Card>
- <Modal
- title={t('确认取消密码登录')}
- visible={showPasswordLoginConfirmModal}
- onOk={handlePasswordLoginConfirm}
- onCancel={() => {
- setShowPasswordLoginConfirmModal(false);
- formApiRef.current.setValue('PasswordLoginEnabled', true);
- }}
- okText={t('确认')}
- cancelText={t('取消')}
- >
- <p>
- {t(
- '您确定要取消密码登录功能吗?这可能会影响用户的登录方式。',
- )}
- </p>
- </Modal>
- </div>
- )}
- </Form>
- ) : (
- <div
- style={{
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- height: '100vh',
- }}
- >
- <Spin size='large' />
- </div>
- )}
- </div>
- );
- };
- export default SystemSetting;
|