SystemSetting.jsx 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useEffect, useState, useRef } from 'react';
  16. import {
  17. Button,
  18. Form,
  19. Row,
  20. Col,
  21. Typography,
  22. Modal,
  23. Banner,
  24. TagInput,
  25. Spin,
  26. Card,
  27. Radio,
  28. } from '@douyinfe/semi-ui';
  29. const { Text } = Typography;
  30. import {
  31. API,
  32. removeTrailingSlash,
  33. showError,
  34. showSuccess,
  35. toBoolean,
  36. } from '../../helpers';
  37. import axios from 'axios';
  38. import { useTranslation } from 'react-i18next';
  39. const SystemSetting = () => {
  40. const { t } = useTranslation();
  41. let [inputs, setInputs] = useState({
  42. PasswordLoginEnabled: '',
  43. PasswordRegisterEnabled: '',
  44. EmailVerificationEnabled: '',
  45. GitHubOAuthEnabled: '',
  46. GitHubClientId: '',
  47. GitHubClientSecret: '',
  48. 'oidc.enabled': '',
  49. 'oidc.client_id': '',
  50. 'oidc.client_secret': '',
  51. 'oidc.well_known': '',
  52. 'oidc.authorization_endpoint': '',
  53. 'oidc.token_endpoint': '',
  54. 'oidc.user_info_endpoint': '',
  55. Notice: '',
  56. SMTPServer: '',
  57. SMTPPort: '',
  58. SMTPAccount: '',
  59. SMTPFrom: '',
  60. SMTPToken: '',
  61. WorkerUrl: '',
  62. WorkerValidKey: '',
  63. WorkerAllowHttpImageRequestEnabled: '',
  64. Footer: '',
  65. WeChatAuthEnabled: '',
  66. WeChatServerAddress: '',
  67. WeChatServerToken: '',
  68. WeChatAccountQRCodeImageURL: '',
  69. TurnstileCheckEnabled: '',
  70. TurnstileSiteKey: '',
  71. TurnstileSecretKey: '',
  72. RegisterEnabled: '',
  73. EmailDomainRestrictionEnabled: '',
  74. EmailAliasRestrictionEnabled: '',
  75. SMTPSSLEnabled: '',
  76. EmailDomainWhitelist: [],
  77. TelegramOAuthEnabled: '',
  78. TelegramBotToken: '',
  79. TelegramBotName: '',
  80. LinuxDOOAuthEnabled: '',
  81. LinuxDOClientId: '',
  82. LinuxDOClientSecret: '',
  83. LinuxDOMinimumTrustLevel: '',
  84. ServerAddress: '',
  85. // SSRF防护配置
  86. 'fetch_setting.enable_ssrf_protection': true,
  87. 'fetch_setting.allow_private_ip': '',
  88. 'fetch_setting.domain_filter_mode': false, // true 白名单,false 黑名单
  89. 'fetch_setting.ip_filter_mode': false, // true 白名单,false 黑名单
  90. 'fetch_setting.domain_list': [],
  91. 'fetch_setting.ip_list': [],
  92. 'fetch_setting.allowed_ports': [],
  93. 'fetch_setting.apply_ip_filter_for_domain': false,
  94. });
  95. const [originInputs, setOriginInputs] = useState({});
  96. const [loading, setLoading] = useState(false);
  97. const [isLoaded, setIsLoaded] = useState(false);
  98. const formApiRef = useRef(null);
  99. const [emailDomainWhitelist, setEmailDomainWhitelist] = useState([]);
  100. const [showPasswordLoginConfirmModal, setShowPasswordLoginConfirmModal] =
  101. useState(false);
  102. const [linuxDOOAuthEnabled, setLinuxDOOAuthEnabled] = useState(false);
  103. const [emailToAdd, setEmailToAdd] = useState('');
  104. const [domainFilterMode, setDomainFilterMode] = useState(true);
  105. const [ipFilterMode, setIpFilterMode] = useState(true);
  106. const [domainList, setDomainList] = useState([]);
  107. const [ipList, setIpList] = useState([]);
  108. const [allowedPorts, setAllowedPorts] = useState([]);
  109. const getOptions = async () => {
  110. setLoading(true);
  111. const res = await API.get('/api/option/');
  112. const { success, message, data } = res.data;
  113. if (success) {
  114. let newInputs = {};
  115. data.forEach((item) => {
  116. switch (item.key) {
  117. case 'TopupGroupRatio':
  118. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  119. break;
  120. case 'EmailDomainWhitelist':
  121. setEmailDomainWhitelist(item.value ? item.value.split(',') : []);
  122. break;
  123. case 'fetch_setting.allow_private_ip':
  124. case 'fetch_setting.enable_ssrf_protection':
  125. case 'fetch_setting.domain_filter_mode':
  126. case 'fetch_setting.ip_filter_mode':
  127. case 'fetch_setting.apply_ip_filter_for_domain':
  128. item.value = toBoolean(item.value);
  129. break;
  130. case 'fetch_setting.domain_list':
  131. try {
  132. const domains = item.value ? JSON.parse(item.value) : [];
  133. setDomainList(Array.isArray(domains) ? domains : []);
  134. } catch (e) {
  135. setDomainList([]);
  136. }
  137. break;
  138. case 'fetch_setting.ip_list':
  139. try {
  140. const ips = item.value ? JSON.parse(item.value) : [];
  141. setIpList(Array.isArray(ips) ? ips : []);
  142. } catch (e) {
  143. setIpList([]);
  144. }
  145. break;
  146. case 'fetch_setting.allowed_ports':
  147. try {
  148. const ports = item.value ? JSON.parse(item.value) : [];
  149. setAllowedPorts(Array.isArray(ports) ? ports : []);
  150. } catch (e) {
  151. setAllowedPorts(['80', '443', '8080', '8443']);
  152. }
  153. break;
  154. case 'PasswordLoginEnabled':
  155. case 'PasswordRegisterEnabled':
  156. case 'EmailVerificationEnabled':
  157. case 'GitHubOAuthEnabled':
  158. case 'WeChatAuthEnabled':
  159. case 'TelegramOAuthEnabled':
  160. case 'RegisterEnabled':
  161. case 'TurnstileCheckEnabled':
  162. case 'EmailDomainRestrictionEnabled':
  163. case 'EmailAliasRestrictionEnabled':
  164. case 'SMTPSSLEnabled':
  165. case 'LinuxDOOAuthEnabled':
  166. case 'oidc.enabled':
  167. case 'WorkerAllowHttpImageRequestEnabled':
  168. item.value = toBoolean(item.value);
  169. break;
  170. case 'Price':
  171. case 'MinTopUp':
  172. item.value = parseFloat(item.value);
  173. break;
  174. default:
  175. break;
  176. }
  177. newInputs[item.key] = item.value;
  178. });
  179. setInputs(newInputs);
  180. setOriginInputs(newInputs);
  181. // 同步模式布尔到本地状态
  182. if (typeof newInputs['fetch_setting.domain_filter_mode'] !== 'undefined') {
  183. setDomainFilterMode(!!newInputs['fetch_setting.domain_filter_mode']);
  184. }
  185. if (typeof newInputs['fetch_setting.ip_filter_mode'] !== 'undefined') {
  186. setIpFilterMode(!!newInputs['fetch_setting.ip_filter_mode']);
  187. }
  188. if (formApiRef.current) {
  189. formApiRef.current.setValues(newInputs);
  190. }
  191. setIsLoaded(true);
  192. } else {
  193. showError(message);
  194. }
  195. setLoading(false);
  196. };
  197. useEffect(() => {
  198. getOptions();
  199. }, []);
  200. const updateOptions = async (options) => {
  201. setLoading(true);
  202. try {
  203. // 分离 checkbox 类型的选项和其他选项
  204. const checkboxOptions = options.filter((opt) =>
  205. opt.key.toLowerCase().endsWith('enabled'),
  206. );
  207. const otherOptions = options.filter(
  208. (opt) => !opt.key.toLowerCase().endsWith('enabled'),
  209. );
  210. // 处理 checkbox 类型的选项
  211. for (const opt of checkboxOptions) {
  212. const res = await API.put('/api/option/', {
  213. key: opt.key,
  214. value: opt.value.toString(),
  215. });
  216. if (!res.data.success) {
  217. showError(res.data.message);
  218. return;
  219. }
  220. }
  221. // 处理其他选项
  222. if (otherOptions.length > 0) {
  223. const requestQueue = otherOptions.map((opt) =>
  224. API.put('/api/option/', {
  225. key: opt.key,
  226. value:
  227. typeof opt.value === 'boolean' ? opt.value.toString() : opt.value,
  228. }),
  229. );
  230. const results = await Promise.all(requestQueue);
  231. // 检查所有请求是否成功
  232. const errorResults = results.filter((res) => !res.data.success);
  233. errorResults.forEach((res) => {
  234. showError(res.data.message);
  235. });
  236. }
  237. showSuccess(t('更新成功'));
  238. // 更新本地状态
  239. const newInputs = { ...inputs };
  240. options.forEach((opt) => {
  241. newInputs[opt.key] = opt.value;
  242. });
  243. setInputs(newInputs);
  244. } catch (error) {
  245. showError(t('更新失败'));
  246. }
  247. setLoading(false);
  248. };
  249. const handleFormChange = (values) => {
  250. setInputs(values);
  251. };
  252. const submitWorker = async () => {
  253. let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
  254. const options = [
  255. { key: 'WorkerUrl', value: WorkerUrl },
  256. {
  257. key: 'WorkerAllowHttpImageRequestEnabled',
  258. value: inputs.WorkerAllowHttpImageRequestEnabled ? 'true' : 'false',
  259. },
  260. ];
  261. if (inputs.WorkerValidKey !== '' || WorkerUrl === '') {
  262. options.push({ key: 'WorkerValidKey', value: inputs.WorkerValidKey });
  263. }
  264. await updateOptions(options);
  265. };
  266. const submitServerAddress = async () => {
  267. let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
  268. await updateOptions([{ key: 'ServerAddress', value: ServerAddress }]);
  269. };
  270. const submitSMTP = async () => {
  271. const options = [];
  272. if (originInputs['SMTPServer'] !== inputs.SMTPServer) {
  273. options.push({ key: 'SMTPServer', value: inputs.SMTPServer });
  274. }
  275. if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
  276. options.push({ key: 'SMTPAccount', value: inputs.SMTPAccount });
  277. }
  278. if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) {
  279. options.push({ key: 'SMTPFrom', value: inputs.SMTPFrom });
  280. }
  281. if (
  282. originInputs['SMTPPort'] !== inputs.SMTPPort &&
  283. inputs.SMTPPort !== ''
  284. ) {
  285. options.push({ key: 'SMTPPort', value: inputs.SMTPPort });
  286. }
  287. if (
  288. originInputs['SMTPToken'] !== inputs.SMTPToken &&
  289. inputs.SMTPToken !== ''
  290. ) {
  291. options.push({ key: 'SMTPToken', value: inputs.SMTPToken });
  292. }
  293. if (options.length > 0) {
  294. await updateOptions(options);
  295. }
  296. };
  297. const submitEmailDomainWhitelist = async () => {
  298. if (Array.isArray(emailDomainWhitelist)) {
  299. await updateOptions([
  300. {
  301. key: 'EmailDomainWhitelist',
  302. value: emailDomainWhitelist.join(','),
  303. },
  304. ]);
  305. } else {
  306. showError(t('邮箱域名白名单格式不正确'));
  307. }
  308. };
  309. const submitSSRF = async () => {
  310. const options = [];
  311. // 处理域名过滤模式与列表
  312. options.push({
  313. key: 'fetch_setting.domain_filter_mode',
  314. value: domainFilterMode,
  315. });
  316. if (Array.isArray(domainList)) {
  317. options.push({
  318. key: 'fetch_setting.domain_list',
  319. value: JSON.stringify(domainList),
  320. });
  321. }
  322. // 处理IP过滤模式与列表
  323. options.push({
  324. key: 'fetch_setting.ip_filter_mode',
  325. value: ipFilterMode,
  326. });
  327. if (Array.isArray(ipList)) {
  328. options.push({
  329. key: 'fetch_setting.ip_list',
  330. value: JSON.stringify(ipList),
  331. });
  332. }
  333. // 处理端口配置
  334. if (Array.isArray(allowedPorts)) {
  335. options.push({
  336. key: 'fetch_setting.allowed_ports',
  337. value: JSON.stringify(allowedPorts),
  338. });
  339. }
  340. if (options.length > 0) {
  341. await updateOptions(options);
  342. }
  343. };
  344. const handleAddEmail = () => {
  345. if (emailToAdd && emailToAdd.trim() !== '') {
  346. const domain = emailToAdd.trim();
  347. // 验证域名格式
  348. const domainRegex =
  349. /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
  350. if (!domainRegex.test(domain)) {
  351. showError(t('邮箱域名格式不正确,请输入有效的域名,如 gmail.com'));
  352. return;
  353. }
  354. // 检查是否已存在
  355. if (emailDomainWhitelist.includes(domain)) {
  356. showError(t('该域名已存在于白名单中'));
  357. return;
  358. }
  359. setEmailDomainWhitelist([...emailDomainWhitelist, domain]);
  360. setEmailToAdd('');
  361. showSuccess(t('已添加到白名单'));
  362. }
  363. };
  364. const submitWeChat = async () => {
  365. const options = [];
  366. if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
  367. options.push({
  368. key: 'WeChatServerAddress',
  369. value: removeTrailingSlash(inputs.WeChatServerAddress),
  370. });
  371. }
  372. if (
  373. originInputs['WeChatAccountQRCodeImageURL'] !==
  374. inputs.WeChatAccountQRCodeImageURL
  375. ) {
  376. options.push({
  377. key: 'WeChatAccountQRCodeImageURL',
  378. value: inputs.WeChatAccountQRCodeImageURL,
  379. });
  380. }
  381. if (
  382. originInputs['WeChatServerToken'] !== inputs.WeChatServerToken &&
  383. inputs.WeChatServerToken !== ''
  384. ) {
  385. options.push({
  386. key: 'WeChatServerToken',
  387. value: inputs.WeChatServerToken,
  388. });
  389. }
  390. if (options.length > 0) {
  391. await updateOptions(options);
  392. }
  393. };
  394. const submitGitHubOAuth = async () => {
  395. const options = [];
  396. if (originInputs['GitHubClientId'] !== inputs.GitHubClientId) {
  397. options.push({ key: 'GitHubClientId', value: inputs.GitHubClientId });
  398. }
  399. if (
  400. originInputs['GitHubClientSecret'] !== inputs.GitHubClientSecret &&
  401. inputs.GitHubClientSecret !== ''
  402. ) {
  403. options.push({
  404. key: 'GitHubClientSecret',
  405. value: inputs.GitHubClientSecret,
  406. });
  407. }
  408. if (options.length > 0) {
  409. await updateOptions(options);
  410. }
  411. };
  412. const submitOIDCSettings = async () => {
  413. if (inputs['oidc.well_known'] && inputs['oidc.well_known'] !== '') {
  414. if (
  415. !inputs['oidc.well_known'].startsWith('http://') &&
  416. !inputs['oidc.well_known'].startsWith('https://')
  417. ) {
  418. showError(t('Well-Known URL 必须以 http:// 或 https:// 开头'));
  419. return;
  420. }
  421. try {
  422. const res = await axios.create().get(inputs['oidc.well_known']);
  423. inputs['oidc.authorization_endpoint'] =
  424. res.data['authorization_endpoint'];
  425. inputs['oidc.token_endpoint'] = res.data['token_endpoint'];
  426. inputs['oidc.user_info_endpoint'] = res.data['userinfo_endpoint'];
  427. showSuccess(t('获取 OIDC 配置成功!'));
  428. } catch (err) {
  429. console.error(err);
  430. showError(
  431. t('获取 OIDC 配置失败,请检查网络状况和 Well-Known URL 是否正确'),
  432. );
  433. return;
  434. }
  435. }
  436. const options = [];
  437. if (originInputs['oidc.well_known'] !== inputs['oidc.well_known']) {
  438. options.push({
  439. key: 'oidc.well_known',
  440. value: inputs['oidc.well_known'],
  441. });
  442. }
  443. if (originInputs['oidc.client_id'] !== inputs['oidc.client_id']) {
  444. options.push({ key: 'oidc.client_id', value: inputs['oidc.client_id'] });
  445. }
  446. if (
  447. originInputs['oidc.client_secret'] !== inputs['oidc.client_secret'] &&
  448. inputs['oidc.client_secret'] !== ''
  449. ) {
  450. options.push({
  451. key: 'oidc.client_secret',
  452. value: inputs['oidc.client_secret'],
  453. });
  454. }
  455. if (
  456. originInputs['oidc.authorization_endpoint'] !==
  457. inputs['oidc.authorization_endpoint']
  458. ) {
  459. options.push({
  460. key: 'oidc.authorization_endpoint',
  461. value: inputs['oidc.authorization_endpoint'],
  462. });
  463. }
  464. if (originInputs['oidc.token_endpoint'] !== inputs['oidc.token_endpoint']) {
  465. options.push({
  466. key: 'oidc.token_endpoint',
  467. value: inputs['oidc.token_endpoint'],
  468. });
  469. }
  470. if (
  471. originInputs['oidc.user_info_endpoint'] !==
  472. inputs['oidc.user_info_endpoint']
  473. ) {
  474. options.push({
  475. key: 'oidc.user_info_endpoint',
  476. value: inputs['oidc.user_info_endpoint'],
  477. });
  478. }
  479. if (options.length > 0) {
  480. await updateOptions(options);
  481. }
  482. };
  483. const submitTelegramSettings = async () => {
  484. const options = [
  485. { key: 'TelegramBotToken', value: inputs.TelegramBotToken },
  486. { key: 'TelegramBotName', value: inputs.TelegramBotName },
  487. ];
  488. await updateOptions(options);
  489. };
  490. const submitTurnstile = async () => {
  491. const options = [];
  492. if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
  493. options.push({ key: 'TurnstileSiteKey', value: inputs.TurnstileSiteKey });
  494. }
  495. if (
  496. originInputs['TurnstileSecretKey'] !== inputs.TurnstileSecretKey &&
  497. inputs.TurnstileSecretKey !== ''
  498. ) {
  499. options.push({
  500. key: 'TurnstileSecretKey',
  501. value: inputs.TurnstileSecretKey,
  502. });
  503. }
  504. if (options.length > 0) {
  505. await updateOptions(options);
  506. }
  507. };
  508. const submitLinuxDOOAuth = async () => {
  509. const options = [];
  510. if (originInputs['LinuxDOClientId'] !== inputs.LinuxDOClientId) {
  511. options.push({ key: 'LinuxDOClientId', value: inputs.LinuxDOClientId });
  512. }
  513. if (
  514. originInputs['LinuxDOClientSecret'] !== inputs.LinuxDOClientSecret &&
  515. inputs.LinuxDOClientSecret !== ''
  516. ) {
  517. options.push({
  518. key: 'LinuxDOClientSecret',
  519. value: inputs.LinuxDOClientSecret,
  520. });
  521. }
  522. if (
  523. originInputs['LinuxDOMinimumTrustLevel'] !==
  524. inputs.LinuxDOMinimumTrustLevel
  525. ) {
  526. options.push({
  527. key: 'LinuxDOMinimumTrustLevel',
  528. value: inputs.LinuxDOMinimumTrustLevel,
  529. });
  530. }
  531. if (options.length > 0) {
  532. await updateOptions(options);
  533. }
  534. };
  535. const handleCheckboxChange = async (optionKey, event) => {
  536. const value = event.target.checked;
  537. if (optionKey === 'PasswordLoginEnabled' && !value) {
  538. setShowPasswordLoginConfirmModal(true);
  539. } else {
  540. await updateOptions([{ key: optionKey, value }]);
  541. }
  542. if (optionKey === 'LinuxDOOAuthEnabled') {
  543. setLinuxDOOAuthEnabled(value);
  544. }
  545. };
  546. const handlePasswordLoginConfirm = async () => {
  547. await updateOptions([{ key: 'PasswordLoginEnabled', value: false }]);
  548. setShowPasswordLoginConfirmModal(false);
  549. };
  550. return (
  551. <div>
  552. {isLoaded ? (
  553. <Form
  554. initValues={inputs}
  555. onValueChange={handleFormChange}
  556. getFormApi={(api) => (formApiRef.current = api)}
  557. >
  558. {({ formState, values, formApi }) => (
  559. <div
  560. style={{
  561. display: 'flex',
  562. flexDirection: 'column',
  563. gap: '10px',
  564. marginTop: '10px',
  565. }}
  566. >
  567. <Card>
  568. <Form.Section text={t('通用设置')}>
  569. <Row
  570. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  571. >
  572. <Col xs={24} sm={24} md={24} lg={24} xl={24}>
  573. <Form.Input
  574. field='ServerAddress'
  575. label={t('服务器地址')}
  576. placeholder='https://yourdomain.com'
  577. extraText={t(
  578. '该服务器地址将影响支付回调地址以及默认首页展示的地址,请确保正确配置',
  579. )}
  580. />
  581. </Col>
  582. </Row>
  583. <Button onClick={submitServerAddress}>
  584. {t('更新服务器地址')}
  585. </Button>
  586. </Form.Section>
  587. </Card>
  588. <Card>
  589. <Form.Section text={t('代理设置')}>
  590. <Text>
  591. (支持{' '}
  592. <a
  593. href='https://github.com/Calcium-Ion/new-api-worker'
  594. target='_blank'
  595. rel='noreferrer'
  596. >
  597. new-api-worker
  598. </a>
  599. </Text>
  600. <Row
  601. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  602. >
  603. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  604. <Form.Input
  605. field='WorkerUrl'
  606. label={t('Worker地址')}
  607. placeholder='例如:https://workername.yourdomain.workers.dev'
  608. />
  609. </Col>
  610. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  611. <Form.Input
  612. field='WorkerValidKey'
  613. label={t('Worker密钥')}
  614. placeholder='敏感信息不会发送到前端显示'
  615. type='password'
  616. />
  617. </Col>
  618. </Row>
  619. <Form.Checkbox
  620. field='WorkerAllowHttpImageRequestEnabled'
  621. noLabel
  622. >
  623. {t('允许 HTTP 协议图片请求(适用于自部署代理)')}
  624. </Form.Checkbox>
  625. <Button onClick={submitWorker}>{t('更新Worker设置')}</Button>
  626. </Form.Section>
  627. </Card>
  628. <Card>
  629. <Form.Section text={t('SSRF防护设置')}>
  630. <Text extraText={t('SSRF防护详细说明')}>
  631. {t('配置服务器端请求伪造(SSRF)防护,用于保护内网资源安全')}
  632. </Text>
  633. <Row
  634. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  635. >
  636. <Col xs={24} sm={24} md={24} lg={24} xl={24}>
  637. <Form.Checkbox
  638. field='fetch_setting.enable_ssrf_protection'
  639. noLabel
  640. extraText={t('SSRF防护开关详细说明')}
  641. onChange={(e) =>
  642. handleCheckboxChange('fetch_setting.enable_ssrf_protection', e)
  643. }
  644. >
  645. {t('启用SSRF防护(推荐开启以保护服务器安全)')}
  646. </Form.Checkbox>
  647. </Col>
  648. </Row>
  649. <Row
  650. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  651. style={{ marginTop: 16 }}
  652. >
  653. <Col xs={24} sm={24} md={24} lg={24} xl={24}>
  654. <Form.Checkbox
  655. field='fetch_setting.allow_private_ip'
  656. noLabel
  657. extraText={t('私有IP访问详细说明')}
  658. onChange={(e) =>
  659. handleCheckboxChange('fetch_setting.allow_private_ip', e)
  660. }
  661. >
  662. {t('允许访问私有IP地址(127.0.0.1、192.168.x.x等内网地址)')}
  663. </Form.Checkbox>
  664. </Col>
  665. </Row>
  666. <Row
  667. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  668. style={{ marginTop: 16 }}
  669. >
  670. <Col xs={24} sm={24} md={24} lg={24} xl={24}>
  671. <Form.Checkbox
  672. field='fetch_setting.apply_ip_filter_for_domain'
  673. noLabel
  674. extraText={t('域名IP过滤详细说明')}
  675. onChange={(e) =>
  676. handleCheckboxChange('fetch_setting.apply_ip_filter_for_domain', e)
  677. }
  678. style={{ marginBottom: 8 }}
  679. >
  680. {t('对域名启用 IP 过滤(实验性)')}
  681. </Form.Checkbox>
  682. <Text strong>
  683. {t(domainFilterMode ? '域名白名单' : '域名黑名单')}
  684. </Text>
  685. <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
  686. {t('支持通配符格式,如:example.com, *.api.example.com')}
  687. </Text>
  688. <Radio.Group
  689. type='button'
  690. value={domainFilterMode ? 'whitelist' : 'blacklist'}
  691. onChange={(val) => {
  692. const selected = val && val.target ? val.target.value : val;
  693. const isWhitelist = selected === 'whitelist';
  694. setDomainFilterMode(isWhitelist);
  695. setInputs(prev => ({
  696. ...prev,
  697. 'fetch_setting.domain_filter_mode': isWhitelist,
  698. }));
  699. }}
  700. style={{ marginBottom: 8 }}
  701. >
  702. <Radio value='whitelist'>{t('白名单')}</Radio>
  703. <Radio value='blacklist'>{t('黑名单')}</Radio>
  704. </Radio.Group>
  705. <TagInput
  706. value={domainList}
  707. onChange={(value) => {
  708. setDomainList(value);
  709. // 触发Form的onChange事件
  710. setInputs(prev => ({
  711. ...prev,
  712. 'fetch_setting.domain_list': value
  713. }));
  714. }}
  715. placeholder={t('输入域名后回车,如:example.com')}
  716. style={{ width: '100%' }}
  717. />
  718. </Col>
  719. </Row>
  720. <Row
  721. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  722. style={{ marginTop: 16 }}
  723. >
  724. <Col xs={24} sm={24} md={24} lg={24} xl={24}>
  725. <Text strong>
  726. {t(ipFilterMode ? 'IP白名单' : 'IP黑名单')}
  727. </Text>
  728. <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
  729. {t('支持CIDR格式,如:8.8.8.8, 192.168.1.0/24')}
  730. </Text>
  731. <Radio.Group
  732. type='button'
  733. value={ipFilterMode ? 'whitelist' : 'blacklist'}
  734. onChange={(val) => {
  735. const selected = val && val.target ? val.target.value : val;
  736. const isWhitelist = selected === 'whitelist';
  737. setIpFilterMode(isWhitelist);
  738. setInputs(prev => ({
  739. ...prev,
  740. 'fetch_setting.ip_filter_mode': isWhitelist,
  741. }));
  742. }}
  743. style={{ marginBottom: 8 }}
  744. >
  745. <Radio value='whitelist'>{t('白名单')}</Radio>
  746. <Radio value='blacklist'>{t('黑名单')}</Radio>
  747. </Radio.Group>
  748. <TagInput
  749. value={ipList}
  750. onChange={(value) => {
  751. setIpList(value);
  752. // 触发Form的onChange事件
  753. setInputs(prev => ({
  754. ...prev,
  755. 'fetch_setting.ip_list': value
  756. }));
  757. }}
  758. placeholder={t('输入IP地址后回车,如:8.8.8.8')}
  759. style={{ width: '100%' }}
  760. />
  761. </Col>
  762. </Row>
  763. <Row
  764. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  765. style={{ marginTop: 16 }}
  766. >
  767. <Col xs={24} sm={24} md={24} lg={24} xl={24}>
  768. <Text strong>{t('允许的端口')}</Text>
  769. <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
  770. {t('支持单个端口和端口范围,如:80, 443, 8000-8999')}
  771. </Text>
  772. <TagInput
  773. value={allowedPorts}
  774. onChange={(value) => {
  775. setAllowedPorts(value);
  776. // 触发Form的onChange事件
  777. setInputs(prev => ({
  778. ...prev,
  779. 'fetch_setting.allowed_ports': value
  780. }));
  781. }}
  782. placeholder={t('输入端口后回车,如:80 或 8000-8999')}
  783. style={{ width: '100%' }}
  784. />
  785. <Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
  786. {t('端口配置详细说明')}
  787. </Text>
  788. </Col>
  789. </Row>
  790. <Button onClick={submitSSRF} style={{ marginTop: 16 }}>
  791. {t('更新SSRF防护设置')}
  792. </Button>
  793. </Form.Section>
  794. </Card>
  795. <Card>
  796. <Form.Section text={t('配置登录注册')}>
  797. <Row
  798. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  799. >
  800. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  801. <Form.Checkbox
  802. field='PasswordLoginEnabled'
  803. noLabel
  804. onChange={(e) =>
  805. handleCheckboxChange('PasswordLoginEnabled', e)
  806. }
  807. >
  808. {t('允许通过密码进行登录')}
  809. </Form.Checkbox>
  810. <Form.Checkbox
  811. field='PasswordRegisterEnabled'
  812. noLabel
  813. onChange={(e) =>
  814. handleCheckboxChange('PasswordRegisterEnabled', e)
  815. }
  816. >
  817. {t('允许通过密码进行注册')}
  818. </Form.Checkbox>
  819. <Form.Checkbox
  820. field='EmailVerificationEnabled'
  821. noLabel
  822. onChange={(e) =>
  823. handleCheckboxChange('EmailVerificationEnabled', e)
  824. }
  825. >
  826. {t('通过密码注册时需要进行邮箱验证')}
  827. </Form.Checkbox>
  828. <Form.Checkbox
  829. field='RegisterEnabled'
  830. noLabel
  831. onChange={(e) =>
  832. handleCheckboxChange('RegisterEnabled', e)
  833. }
  834. >
  835. {t('允许新用户注册')}
  836. </Form.Checkbox>
  837. <Form.Checkbox
  838. field='TurnstileCheckEnabled'
  839. noLabel
  840. onChange={(e) =>
  841. handleCheckboxChange('TurnstileCheckEnabled', e)
  842. }
  843. >
  844. {t('允许 Turnstile 用户校验')}
  845. </Form.Checkbox>
  846. </Col>
  847. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  848. <Form.Checkbox
  849. field='GitHubOAuthEnabled'
  850. noLabel
  851. onChange={(e) =>
  852. handleCheckboxChange('GitHubOAuthEnabled', e)
  853. }
  854. >
  855. {t('允许通过 GitHub 账户登录 & 注册')}
  856. </Form.Checkbox>
  857. <Form.Checkbox
  858. field='LinuxDOOAuthEnabled'
  859. noLabel
  860. onChange={(e) =>
  861. handleCheckboxChange('LinuxDOOAuthEnabled', e)
  862. }
  863. >
  864. {t('允许通过 Linux DO 账户登录 & 注册')}
  865. </Form.Checkbox>
  866. <Form.Checkbox
  867. field='WeChatAuthEnabled'
  868. noLabel
  869. onChange={(e) =>
  870. handleCheckboxChange('WeChatAuthEnabled', e)
  871. }
  872. >
  873. {t('允许通过微信登录 & 注册')}
  874. </Form.Checkbox>
  875. <Form.Checkbox
  876. field='TelegramOAuthEnabled'
  877. noLabel
  878. onChange={(e) =>
  879. handleCheckboxChange('TelegramOAuthEnabled', e)
  880. }
  881. >
  882. {t('允许通过 Telegram 进行登录')}
  883. </Form.Checkbox>
  884. <Form.Checkbox
  885. field="['oidc.enabled']"
  886. noLabel
  887. onChange={(e) =>
  888. handleCheckboxChange('oidc.enabled', e)
  889. }
  890. >
  891. {t('允许通过 OIDC 进行登录')}
  892. </Form.Checkbox>
  893. </Col>
  894. </Row>
  895. </Form.Section>
  896. </Card>
  897. <Card>
  898. <Form.Section text={t('配置邮箱域名白名单')}>
  899. <Text>{t('用以防止恶意用户利用临时邮箱批量注册')}</Text>
  900. <Row
  901. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  902. >
  903. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  904. <Form.Checkbox
  905. field='EmailDomainRestrictionEnabled'
  906. noLabel
  907. onChange={(e) =>
  908. handleCheckboxChange(
  909. 'EmailDomainRestrictionEnabled',
  910. e,
  911. )
  912. }
  913. >
  914. 启用邮箱域名白名单
  915. </Form.Checkbox>
  916. </Col>
  917. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  918. <Form.Checkbox
  919. field='EmailAliasRestrictionEnabled'
  920. noLabel
  921. onChange={(e) =>
  922. handleCheckboxChange(
  923. 'EmailAliasRestrictionEnabled',
  924. e,
  925. )
  926. }
  927. >
  928. 启用邮箱别名限制
  929. </Form.Checkbox>
  930. </Col>
  931. </Row>
  932. <TagInput
  933. value={emailDomainWhitelist}
  934. onChange={setEmailDomainWhitelist}
  935. placeholder={t('输入域名后回车')}
  936. style={{ width: '100%', marginTop: 16 }}
  937. />
  938. <Form.Input
  939. placeholder={t('输入要添加的邮箱域名')}
  940. value={emailToAdd}
  941. onChange={(value) => setEmailToAdd(value)}
  942. style={{ marginTop: 16 }}
  943. suffix={
  944. <Button
  945. theme='solid'
  946. type='primary'
  947. onClick={handleAddEmail}
  948. >
  949. {t('添加')}
  950. </Button>
  951. }
  952. onEnterPress={handleAddEmail}
  953. />
  954. <Button
  955. onClick={submitEmailDomainWhitelist}
  956. style={{ marginTop: 10 }}
  957. >
  958. {t('保存邮箱域名白名单设置')}
  959. </Button>
  960. </Form.Section>
  961. </Card>
  962. <Card>
  963. <Form.Section text={t('配置 SMTP')}>
  964. <Text>{t('用以支持系统的邮件发送')}</Text>
  965. <Row
  966. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  967. >
  968. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  969. <Form.Input
  970. field='SMTPServer'
  971. label={t('SMTP 服务器地址')}
  972. />
  973. </Col>
  974. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  975. <Form.Input field='SMTPPort' label={t('SMTP 端口')} />
  976. </Col>
  977. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  978. <Form.Input field='SMTPAccount' label={t('SMTP 账户')} />
  979. </Col>
  980. </Row>
  981. <Row
  982. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  983. style={{ marginTop: 16 }}
  984. >
  985. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  986. <Form.Input
  987. field='SMTPFrom'
  988. label={t('SMTP 发送者邮箱')}
  989. />
  990. </Col>
  991. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  992. <Form.Input
  993. field='SMTPToken'
  994. label={t('SMTP 访问凭证')}
  995. type='password'
  996. placeholder='敏感信息不会发送到前端显示'
  997. />
  998. </Col>
  999. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1000. <Form.Checkbox
  1001. field='SMTPSSLEnabled'
  1002. noLabel
  1003. onChange={(e) =>
  1004. handleCheckboxChange('SMTPSSLEnabled', e)
  1005. }
  1006. >
  1007. {t('启用SMTP SSL')}
  1008. </Form.Checkbox>
  1009. </Col>
  1010. </Row>
  1011. <Button onClick={submitSMTP}>{t('保存 SMTP 设置')}</Button>
  1012. </Form.Section>
  1013. </Card>
  1014. <Card>
  1015. <Form.Section text={t('配置 OIDC')}>
  1016. <Text>
  1017. {t(
  1018. '用以支持通过 OIDC 登录,例如 Okta、Auth0 等兼容 OIDC 协议的 IdP',
  1019. )}
  1020. </Text>
  1021. <Banner
  1022. type='info'
  1023. description={`${t('主页链接填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')},${t('重定向 URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')}/oauth/oidc`}
  1024. style={{ marginBottom: 20, marginTop: 16 }}
  1025. />
  1026. <Text>
  1027. {t(
  1028. '若你的 OIDC Provider 支持 Discovery Endpoint,你可以仅填写 OIDC Well-Known URL,系统会自动获取 OIDC 配置',
  1029. )}
  1030. </Text>
  1031. <Row
  1032. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1033. >
  1034. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1035. <Form.Input
  1036. field="['oidc.well_known']"
  1037. label={t('Well-Known URL')}
  1038. placeholder={t('请输入 OIDC 的 Well-Known URL')}
  1039. />
  1040. </Col>
  1041. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1042. <Form.Input
  1043. field="['oidc.client_id']"
  1044. label={t('Client ID')}
  1045. placeholder={t('输入 OIDC 的 Client ID')}
  1046. />
  1047. </Col>
  1048. </Row>
  1049. <Row
  1050. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1051. >
  1052. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1053. <Form.Input
  1054. field="['oidc.client_secret']"
  1055. label={t('Client Secret')}
  1056. type='password'
  1057. placeholder={t('敏感信息不会发送到前端显示')}
  1058. />
  1059. </Col>
  1060. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1061. <Form.Input
  1062. field="['oidc.authorization_endpoint']"
  1063. label={t('Authorization Endpoint')}
  1064. placeholder={t('输入 OIDC 的 Authorization Endpoint')}
  1065. />
  1066. </Col>
  1067. </Row>
  1068. <Row
  1069. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1070. >
  1071. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1072. <Form.Input
  1073. field="['oidc.token_endpoint']"
  1074. label={t('Token Endpoint')}
  1075. placeholder={t('输入 OIDC 的 Token Endpoint')}
  1076. />
  1077. </Col>
  1078. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1079. <Form.Input
  1080. field="['oidc.user_info_endpoint']"
  1081. label={t('User Info Endpoint')}
  1082. placeholder={t('输入 OIDC 的 Userinfo Endpoint')}
  1083. />
  1084. </Col>
  1085. </Row>
  1086. <Button onClick={submitOIDCSettings}>
  1087. {t('保存 OIDC 设置')}
  1088. </Button>
  1089. </Form.Section>
  1090. </Card>
  1091. <Card>
  1092. <Form.Section text={t('配置 GitHub OAuth App')}>
  1093. <Text>{t('用以支持通过 GitHub 进行登录注册')}</Text>
  1094. <Banner
  1095. type='info'
  1096. description={`${t('Homepage URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')},${t('Authorization callback URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')}/oauth/github`}
  1097. style={{ marginBottom: 20, marginTop: 16 }}
  1098. />
  1099. <Row
  1100. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1101. >
  1102. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1103. <Form.Input
  1104. field='GitHubClientId'
  1105. label={t('GitHub Client ID')}
  1106. />
  1107. </Col>
  1108. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1109. <Form.Input
  1110. field='GitHubClientSecret'
  1111. label={t('GitHub Client Secret')}
  1112. type='password'
  1113. placeholder={t('敏感信息不会发送到前端显示')}
  1114. />
  1115. </Col>
  1116. </Row>
  1117. <Button onClick={submitGitHubOAuth}>
  1118. {t('保存 GitHub OAuth 设置')}
  1119. </Button>
  1120. </Form.Section>
  1121. </Card>
  1122. <Card>
  1123. <Form.Section text={t('配置 Linux DO OAuth')}>
  1124. <Text>
  1125. {t('用以支持通过 Linux DO 进行登录注册')}
  1126. <a
  1127. href='https://connect.linux.do/'
  1128. target='_blank'
  1129. rel='noreferrer'
  1130. style={{
  1131. display: 'inline-block',
  1132. marginLeft: 4,
  1133. marginRight: 4,
  1134. }}
  1135. >
  1136. {t('点击此处')}
  1137. </a>
  1138. {t('管理你的 LinuxDO OAuth App')}
  1139. </Text>
  1140. <Banner
  1141. type='info'
  1142. description={`${t('回调 URL 填')} ${inputs.ServerAddress ? inputs.ServerAddress : t('网站地址')}/oauth/linuxdo`}
  1143. style={{ marginBottom: 20, marginTop: 16 }}
  1144. />
  1145. <Row
  1146. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1147. >
  1148. <Col xs={24} sm={24} md={10} lg={10} xl={10}>
  1149. <Form.Input
  1150. field='LinuxDOClientId'
  1151. label={t('Linux DO Client ID')}
  1152. placeholder={t('输入你注册的 LinuxDO OAuth APP 的 ID')}
  1153. />
  1154. </Col>
  1155. <Col xs={24} sm={24} md={10} lg={10} xl={10}>
  1156. <Form.Input
  1157. field='LinuxDOClientSecret'
  1158. label={t('Linux DO Client Secret')}
  1159. type='password'
  1160. placeholder={t('敏感信息不会发送到前端显示')}
  1161. />
  1162. </Col>
  1163. <Col xs={24} sm={24} md={4} lg={4} xl={4}>
  1164. <Form.Input
  1165. field='LinuxDOMinimumTrustLevel'
  1166. label='LinuxDO Minimum Trust Level'
  1167. placeholder='允许注册的最低信任等级'
  1168. />
  1169. </Col>
  1170. </Row>
  1171. <Button onClick={submitLinuxDOOAuth}>
  1172. {t('保存 Linux DO OAuth 设置')}
  1173. </Button>
  1174. </Form.Section>
  1175. </Card>
  1176. <Card>
  1177. <Form.Section text={t('配置 WeChat Server')}>
  1178. <Text>{t('用以支持通过微信进行登录注册')}</Text>
  1179. <Row
  1180. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1181. >
  1182. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1183. <Form.Input
  1184. field='WeChatServerAddress'
  1185. label={t('WeChat Server 服务器地址')}
  1186. />
  1187. </Col>
  1188. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1189. <Form.Input
  1190. field='WeChatServerToken'
  1191. label={t('WeChat Server 访问凭证')}
  1192. type='password'
  1193. placeholder={t('敏感信息不会发送到前端显示')}
  1194. />
  1195. </Col>
  1196. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1197. <Form.Input
  1198. field='WeChatAccountQRCodeImageURL'
  1199. label={t('微信公众号二维码图片链接')}
  1200. />
  1201. </Col>
  1202. </Row>
  1203. <Button onClick={submitWeChat}>
  1204. {t('保存 WeChat Server 设置')}
  1205. </Button>
  1206. </Form.Section>
  1207. </Card>
  1208. <Card>
  1209. <Form.Section text={t('配置 Telegram 登录')}>
  1210. <Text>{t('用以支持通过 Telegram 进行登录注册')}</Text>
  1211. <Row
  1212. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1213. >
  1214. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1215. <Form.Input
  1216. field='TelegramBotToken'
  1217. label={t('Telegram Bot Token')}
  1218. placeholder={t('敏感信息不会发送到前端显示')}
  1219. type='password'
  1220. />
  1221. </Col>
  1222. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1223. <Form.Input
  1224. field='TelegramBotName'
  1225. label={t('Telegram Bot 名称')}
  1226. />
  1227. </Col>
  1228. </Row>
  1229. <Button onClick={submitTelegramSettings}>
  1230. {t('保存 Telegram 登录设置')}
  1231. </Button>
  1232. </Form.Section>
  1233. </Card>
  1234. <Card>
  1235. <Form.Section text={t('配置 Turnstile')}>
  1236. <Text>{t('用以支持用户校验')}</Text>
  1237. <Row
  1238. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1239. >
  1240. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1241. <Form.Input
  1242. field='TurnstileSiteKey'
  1243. label={t('Turnstile Site Key')}
  1244. />
  1245. </Col>
  1246. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1247. <Form.Input
  1248. field='TurnstileSecretKey'
  1249. label={t('Turnstile Secret Key')}
  1250. type='password'
  1251. placeholder={t('敏感信息不会发送到前端显示')}
  1252. />
  1253. </Col>
  1254. </Row>
  1255. <Button onClick={submitTurnstile}>
  1256. {t('保存 Turnstile 设置')}
  1257. </Button>
  1258. </Form.Section>
  1259. </Card>
  1260. <Modal
  1261. title={t('确认取消密码登录')}
  1262. visible={showPasswordLoginConfirmModal}
  1263. onOk={handlePasswordLoginConfirm}
  1264. onCancel={() => {
  1265. setShowPasswordLoginConfirmModal(false);
  1266. formApiRef.current.setValue('PasswordLoginEnabled', true);
  1267. }}
  1268. okText={t('确认')}
  1269. cancelText={t('取消')}
  1270. >
  1271. <p>
  1272. {t(
  1273. '您确定要取消密码登录功能吗?这可能会影响用户的登录方式。',
  1274. )}
  1275. </p>
  1276. </Modal>
  1277. </div>
  1278. )}
  1279. </Form>
  1280. ) : (
  1281. <div
  1282. style={{
  1283. display: 'flex',
  1284. justifyContent: 'center',
  1285. alignItems: 'center',
  1286. height: '100vh',
  1287. }}
  1288. >
  1289. <Spin size='large' />
  1290. </div>
  1291. )}
  1292. </div>
  1293. );
  1294. };
  1295. export default SystemSetting;