SystemSetting.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. import React, { useEffect, useState, useRef } from 'react';
  2. import {
  3. Button,
  4. Form,
  5. Row,
  6. Col,
  7. Typography,
  8. Modal,
  9. Banner,
  10. TagInput,
  11. Spin,
  12. Card,
  13. } from '@douyinfe/semi-ui';
  14. const { Text } = Typography;
  15. import {
  16. API,
  17. removeTrailingSlash,
  18. showError,
  19. showSuccess,
  20. verifyJSON,
  21. } from '../../helpers';
  22. import axios from 'axios';
  23. const SystemSetting = () => {
  24. let [inputs, setInputs] = useState({
  25. PasswordLoginEnabled: '',
  26. PasswordRegisterEnabled: '',
  27. EmailVerificationEnabled: '',
  28. GitHubOAuthEnabled: '',
  29. GitHubClientId: '',
  30. GitHubClientSecret: '',
  31. 'oidc.enabled': '',
  32. 'oidc.client_id': '',
  33. 'oidc.client_secret': '',
  34. 'oidc.well_known': '',
  35. 'oidc.authorization_endpoint': '',
  36. 'oidc.token_endpoint': '',
  37. 'oidc.user_info_endpoint': '',
  38. Notice: '',
  39. SMTPServer: '',
  40. SMTPPort: '',
  41. SMTPAccount: '',
  42. SMTPFrom: '',
  43. SMTPToken: '',
  44. ServerAddress: '',
  45. WorkerUrl: '',
  46. WorkerValidKey: '',
  47. WorkerAllowHttpImageRequestEnabled: '',
  48. EpayId: '',
  49. EpayKey: '',
  50. Price: 7.3,
  51. MinTopUp: 1,
  52. TopupGroupRatio: '',
  53. PayAddress: '',
  54. CustomCallbackAddress: '',
  55. Footer: '',
  56. WeChatAuthEnabled: '',
  57. WeChatServerAddress: '',
  58. WeChatServerToken: '',
  59. WeChatAccountQRCodeImageURL: '',
  60. TurnstileCheckEnabled: '',
  61. TurnstileSiteKey: '',
  62. TurnstileSecretKey: '',
  63. RegisterEnabled: '',
  64. EmailDomainRestrictionEnabled: '',
  65. EmailAliasRestrictionEnabled: '',
  66. SMTPSSLEnabled: '',
  67. EmailDomainWhitelist: [],
  68. // telegram login
  69. TelegramOAuthEnabled: '',
  70. TelegramBotToken: '',
  71. TelegramBotName: '',
  72. LinuxDOOAuthEnabled: '',
  73. LinuxDOClientId: '',
  74. LinuxDOClientSecret: '',
  75. PayMethods: '',
  76. });
  77. const [originInputs, setOriginInputs] = useState({});
  78. const [loading, setLoading] = useState(false);
  79. const [isLoaded, setIsLoaded] = useState(false);
  80. const formApiRef = useRef(null);
  81. const [emailDomainWhitelist, setEmailDomainWhitelist] = useState([]);
  82. const [showPasswordLoginConfirmModal, setShowPasswordLoginConfirmModal] =
  83. useState(false);
  84. const [linuxDOOAuthEnabled, setLinuxDOOAuthEnabled] = useState(false);
  85. const [emailToAdd, setEmailToAdd] = useState('');
  86. const getOptions = async () => {
  87. setLoading(true);
  88. const res = await API.get('/api/option/');
  89. const { success, message, data } = res.data;
  90. if (success) {
  91. let newInputs = {};
  92. data.forEach((item) => {
  93. switch (item.key) {
  94. case 'TopupGroupRatio':
  95. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  96. break;
  97. case 'EmailDomainWhitelist':
  98. setEmailDomainWhitelist(item.value ? item.value.split(',') : []);
  99. break;
  100. case 'PasswordLoginEnabled':
  101. case 'PasswordRegisterEnabled':
  102. case 'EmailVerificationEnabled':
  103. case 'GitHubOAuthEnabled':
  104. case 'WeChatAuthEnabled':
  105. case 'TelegramOAuthEnabled':
  106. case 'RegisterEnabled':
  107. case 'TurnstileCheckEnabled':
  108. case 'EmailDomainRestrictionEnabled':
  109. case 'EmailAliasRestrictionEnabled':
  110. case 'SMTPSSLEnabled':
  111. case 'LinuxDOOAuthEnabled':
  112. case 'oidc.enabled':
  113. case 'WorkerAllowHttpImageRequestEnabled':
  114. item.value = item.value === 'true';
  115. break;
  116. case 'Price':
  117. case 'MinTopUp':
  118. item.value = parseFloat(item.value);
  119. break;
  120. default:
  121. break;
  122. }
  123. newInputs[item.key] = item.value;
  124. });
  125. setInputs(newInputs);
  126. setOriginInputs(newInputs);
  127. if (formApiRef.current) {
  128. formApiRef.current.setValues(newInputs);
  129. }
  130. setIsLoaded(true);
  131. } else {
  132. showError(message);
  133. }
  134. setLoading(false);
  135. };
  136. useEffect(() => {
  137. getOptions();
  138. }, []);
  139. const updateOptions = async (options) => {
  140. setLoading(true);
  141. try {
  142. // 分离 checkbox 类型的选项和其他选项
  143. const checkboxOptions = options.filter((opt) =>
  144. opt.key.toLowerCase().endsWith('enabled'),
  145. );
  146. const otherOptions = options.filter(
  147. (opt) => !opt.key.toLowerCase().endsWith('enabled'),
  148. );
  149. // 处理 checkbox 类型的选项
  150. for (const opt of checkboxOptions) {
  151. const res = await API.put('/api/option/', {
  152. key: opt.key,
  153. value: opt.value.toString(),
  154. });
  155. if (!res.data.success) {
  156. showError(res.data.message);
  157. return;
  158. }
  159. }
  160. // 处理其他选项
  161. if (otherOptions.length > 0) {
  162. const requestQueue = otherOptions.map((opt) =>
  163. API.put('/api/option/', {
  164. key: opt.key,
  165. value:
  166. typeof opt.value === 'boolean' ? opt.value.toString() : opt.value,
  167. }),
  168. );
  169. const results = await Promise.all(requestQueue);
  170. // 检查所有请求是否成功
  171. const errorResults = results.filter((res) => !res.data.success);
  172. errorResults.forEach((res) => {
  173. showError(res.data.message);
  174. });
  175. }
  176. showSuccess('更新成功');
  177. // 更新本地状态
  178. const newInputs = { ...inputs };
  179. options.forEach((opt) => {
  180. newInputs[opt.key] = opt.value;
  181. });
  182. setInputs(newInputs);
  183. } catch (error) {
  184. showError('更新失败');
  185. }
  186. setLoading(false);
  187. };
  188. const handleFormChange = (values) => {
  189. setInputs(values);
  190. };
  191. const submitServerAddress = async () => {
  192. let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
  193. await updateOptions([{ key: 'ServerAddress', value: ServerAddress }]);
  194. };
  195. const submitWorker = async () => {
  196. let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
  197. const options = [
  198. { key: 'WorkerUrl', value: WorkerUrl },
  199. {
  200. key: 'WorkerAllowHttpImageRequestEnabled',
  201. value: inputs.WorkerAllowHttpImageRequestEnabled ? 'true' : 'false',
  202. },
  203. ];
  204. if (inputs.WorkerValidKey !== '' || WorkerUrl === '') {
  205. options.push({ key: 'WorkerValidKey', value: inputs.WorkerValidKey });
  206. }
  207. await updateOptions(options);
  208. };
  209. const submitPayAddress = async () => {
  210. if (inputs.ServerAddress === '') {
  211. showError('请先填写服务器地址');
  212. return;
  213. }
  214. if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
  215. if (!verifyJSON(inputs.TopupGroupRatio)) {
  216. showError('充值分组倍率不是合法的 JSON 字符串');
  217. return;
  218. }
  219. }
  220. if (originInputs['PayMethods'] !== inputs.PayMethods) {
  221. if (!verifyJSON(inputs.PayMethods)) {
  222. showError('充值方式设置不是合法的 JSON 字符串');
  223. return;
  224. }
  225. }
  226. const options = [
  227. { key: 'PayAddress', value: removeTrailingSlash(inputs.PayAddress) },
  228. ];
  229. if (inputs.EpayId !== '') {
  230. options.push({ key: 'EpayId', value: inputs.EpayId });
  231. }
  232. if (inputs.EpayKey !== undefined && inputs.EpayKey !== '') {
  233. options.push({ key: 'EpayKey', value: inputs.EpayKey });
  234. }
  235. if (inputs.Price !== '') {
  236. options.push({ key: 'Price', value: inputs.Price.toString() });
  237. }
  238. if (inputs.MinTopUp !== '') {
  239. options.push({ key: 'MinTopUp', value: inputs.MinTopUp.toString() });
  240. }
  241. if (inputs.CustomCallbackAddress !== '') {
  242. options.push({
  243. key: 'CustomCallbackAddress',
  244. value: inputs.CustomCallbackAddress,
  245. });
  246. }
  247. if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
  248. options.push({ key: 'TopupGroupRatio', value: inputs.TopupGroupRatio });
  249. }
  250. if (originInputs['PayMethods'] !== inputs.PayMethods) {
  251. options.push({ key: 'PayMethods', value: inputs.PayMethods });
  252. }
  253. await updateOptions(options);
  254. };
  255. const submitSMTP = async () => {
  256. const options = [];
  257. if (originInputs['SMTPServer'] !== inputs.SMTPServer) {
  258. options.push({ key: 'SMTPServer', value: inputs.SMTPServer });
  259. }
  260. if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
  261. options.push({ key: 'SMTPAccount', value: inputs.SMTPAccount });
  262. }
  263. if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) {
  264. options.push({ key: 'SMTPFrom', value: inputs.SMTPFrom });
  265. }
  266. if (
  267. originInputs['SMTPPort'] !== inputs.SMTPPort &&
  268. inputs.SMTPPort !== ''
  269. ) {
  270. options.push({ key: 'SMTPPort', value: inputs.SMTPPort });
  271. }
  272. if (
  273. originInputs['SMTPToken'] !== inputs.SMTPToken &&
  274. inputs.SMTPToken !== ''
  275. ) {
  276. options.push({ key: 'SMTPToken', value: inputs.SMTPToken });
  277. }
  278. if (options.length > 0) {
  279. await updateOptions(options);
  280. }
  281. };
  282. const submitEmailDomainWhitelist = async () => {
  283. if (Array.isArray(emailDomainWhitelist)) {
  284. await updateOptions([
  285. {
  286. key: 'EmailDomainWhitelist',
  287. value: emailDomainWhitelist.join(','),
  288. },
  289. ]);
  290. } else {
  291. showError('邮箱域名白名单格式不正确');
  292. }
  293. };
  294. const handleAddEmail = () => {
  295. if (emailToAdd && emailToAdd.trim() !== '') {
  296. const domain = emailToAdd.trim();
  297. // 验证域名格式
  298. const domainRegex =
  299. /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
  300. if (!domainRegex.test(domain)) {
  301. showError('邮箱域名格式不正确,请输入有效的域名,如 gmail.com');
  302. return;
  303. }
  304. // 检查是否已存在
  305. if (emailDomainWhitelist.includes(domain)) {
  306. showError('该域名已存在于白名单中');
  307. return;
  308. }
  309. setEmailDomainWhitelist([...emailDomainWhitelist, domain]);
  310. setEmailToAdd('');
  311. showSuccess('已添加到白名单');
  312. }
  313. };
  314. const submitWeChat = async () => {
  315. const options = [];
  316. if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
  317. options.push({
  318. key: 'WeChatServerAddress',
  319. value: removeTrailingSlash(inputs.WeChatServerAddress),
  320. });
  321. }
  322. if (
  323. originInputs['WeChatAccountQRCodeImageURL'] !==
  324. inputs.WeChatAccountQRCodeImageURL
  325. ) {
  326. options.push({
  327. key: 'WeChatAccountQRCodeImageURL',
  328. value: inputs.WeChatAccountQRCodeImageURL,
  329. });
  330. }
  331. if (
  332. originInputs['WeChatServerToken'] !== inputs.WeChatServerToken &&
  333. inputs.WeChatServerToken !== ''
  334. ) {
  335. options.push({
  336. key: 'WeChatServerToken',
  337. value: inputs.WeChatServerToken,
  338. });
  339. }
  340. if (options.length > 0) {
  341. await updateOptions(options);
  342. }
  343. };
  344. const submitGitHubOAuth = async () => {
  345. const options = [];
  346. if (originInputs['GitHubClientId'] !== inputs.GitHubClientId) {
  347. options.push({ key: 'GitHubClientId', value: inputs.GitHubClientId });
  348. }
  349. if (
  350. originInputs['GitHubClientSecret'] !== inputs.GitHubClientSecret &&
  351. inputs.GitHubClientSecret !== ''
  352. ) {
  353. options.push({
  354. key: 'GitHubClientSecret',
  355. value: inputs.GitHubClientSecret,
  356. });
  357. }
  358. if (options.length > 0) {
  359. await updateOptions(options);
  360. }
  361. };
  362. const submitOIDCSettings = async () => {
  363. if (inputs['oidc.well_known'] && inputs['oidc.well_known'] !== '') {
  364. if (
  365. !inputs['oidc.well_known'].startsWith('http://') &&
  366. !inputs['oidc.well_known'].startsWith('https://')
  367. ) {
  368. showError('Well-Known URL 必须以 http:// 或 https:// 开头');
  369. return;
  370. }
  371. try {
  372. const res = await axios.create().get(inputs['oidc.well_known']);
  373. inputs['oidc.authorization_endpoint'] =
  374. res.data['authorization_endpoint'];
  375. inputs['oidc.token_endpoint'] = res.data['token_endpoint'];
  376. inputs['oidc.user_info_endpoint'] = res.data['userinfo_endpoint'];
  377. showSuccess('获取 OIDC 配置成功!');
  378. } catch (err) {
  379. console.error(err);
  380. showError(
  381. '获取 OIDC 配置失败,请检查网络状况和 Well-Known URL 是否正确',
  382. );
  383. return;
  384. }
  385. }
  386. const options = [];
  387. if (originInputs['oidc.well_known'] !== inputs['oidc.well_known']) {
  388. options.push({
  389. key: 'oidc.well_known',
  390. value: inputs['oidc.well_known'],
  391. });
  392. }
  393. if (originInputs['oidc.client_id'] !== inputs['oidc.client_id']) {
  394. options.push({ key: 'oidc.client_id', value: inputs['oidc.client_id'] });
  395. }
  396. if (
  397. originInputs['oidc.client_secret'] !== inputs['oidc.client_secret'] &&
  398. inputs['oidc.client_secret'] !== ''
  399. ) {
  400. options.push({
  401. key: 'oidc.client_secret',
  402. value: inputs['oidc.client_secret'],
  403. });
  404. }
  405. if (
  406. originInputs['oidc.authorization_endpoint'] !==
  407. inputs['oidc.authorization_endpoint']
  408. ) {
  409. options.push({
  410. key: 'oidc.authorization_endpoint',
  411. value: inputs['oidc.authorization_endpoint'],
  412. });
  413. }
  414. if (originInputs['oidc.token_endpoint'] !== inputs['oidc.token_endpoint']) {
  415. options.push({
  416. key: 'oidc.token_endpoint',
  417. value: inputs['oidc.token_endpoint'],
  418. });
  419. }
  420. if (
  421. originInputs['oidc.user_info_endpoint'] !==
  422. inputs['oidc.user_info_endpoint']
  423. ) {
  424. options.push({
  425. key: 'oidc.user_info_endpoint',
  426. value: inputs['oidc.user_info_endpoint'],
  427. });
  428. }
  429. if (options.length > 0) {
  430. await updateOptions(options);
  431. }
  432. };
  433. const submitTelegramSettings = async () => {
  434. const options = [
  435. { key: 'TelegramBotToken', value: inputs.TelegramBotToken },
  436. { key: 'TelegramBotName', value: inputs.TelegramBotName },
  437. ];
  438. await updateOptions(options);
  439. };
  440. const submitTurnstile = async () => {
  441. const options = [];
  442. if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
  443. options.push({ key: 'TurnstileSiteKey', value: inputs.TurnstileSiteKey });
  444. }
  445. if (
  446. originInputs['TurnstileSecretKey'] !== inputs.TurnstileSecretKey &&
  447. inputs.TurnstileSecretKey !== ''
  448. ) {
  449. options.push({
  450. key: 'TurnstileSecretKey',
  451. value: inputs.TurnstileSecretKey,
  452. });
  453. }
  454. if (options.length > 0) {
  455. await updateOptions(options);
  456. }
  457. };
  458. const submitLinuxDOOAuth = async () => {
  459. const options = [];
  460. if (originInputs['LinuxDOClientId'] !== inputs.LinuxDOClientId) {
  461. options.push({ key: 'LinuxDOClientId', value: inputs.LinuxDOClientId });
  462. }
  463. if (
  464. originInputs['LinuxDOClientSecret'] !== inputs.LinuxDOClientSecret &&
  465. inputs.LinuxDOClientSecret !== ''
  466. ) {
  467. options.push({
  468. key: 'LinuxDOClientSecret',
  469. value: inputs.LinuxDOClientSecret,
  470. });
  471. }
  472. if (options.length > 0) {
  473. await updateOptions(options);
  474. }
  475. };
  476. const handleCheckboxChange = async (optionKey, event) => {
  477. const value = event.target.checked;
  478. if (optionKey === 'PasswordLoginEnabled' && !value) {
  479. setShowPasswordLoginConfirmModal(true);
  480. } else {
  481. await updateOptions([{ key: optionKey, value }]);
  482. }
  483. if (optionKey === 'LinuxDOOAuthEnabled') {
  484. setLinuxDOOAuthEnabled(value);
  485. }
  486. };
  487. const handlePasswordLoginConfirm = async () => {
  488. await updateOptions([{ key: 'PasswordLoginEnabled', value: false }]);
  489. setShowPasswordLoginConfirmModal(false);
  490. };
  491. return (
  492. <div>
  493. {isLoaded ? (
  494. <Form
  495. initValues={inputs}
  496. onValueChange={handleFormChange}
  497. getFormApi={(api) => (formApiRef.current = api)}
  498. >
  499. {({ formState, values, formApi }) => (
  500. <div
  501. style={{
  502. display: 'flex',
  503. flexDirection: 'column',
  504. gap: '10px',
  505. marginTop: '10px',
  506. }}
  507. >
  508. <Card>
  509. <Form.Section text='通用设置'>
  510. <Form.Input
  511. field='ServerAddress'
  512. label='服务器地址'
  513. placeholder='例如:https://yourdomain.com'
  514. style={{ width: '100%' }}
  515. />
  516. <Button onClick={submitServerAddress}>更新服务器地址</Button>
  517. </Form.Section>
  518. </Card>
  519. <Card>
  520. <Form.Section text='代理设置'>
  521. <Text>
  522. (支持{' '}
  523. <a
  524. href='https://github.com/Calcium-Ion/new-api-worker'
  525. target='_blank'
  526. rel='noreferrer'
  527. >
  528. new-api-worker
  529. </a>
  530. </Text>
  531. <Row
  532. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  533. >
  534. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  535. <Form.Input
  536. field='WorkerUrl'
  537. label='Worker地址'
  538. placeholder='例如:https://workername.yourdomain.workers.dev'
  539. />
  540. </Col>
  541. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  542. <Form.Input
  543. field='WorkerValidKey'
  544. label='Worker密钥'
  545. placeholder='敏感信息不会发送到前端显示'
  546. type='password'
  547. />
  548. </Col>
  549. </Row>
  550. <Form.Checkbox
  551. field='WorkerAllowHttpImageRequestEnabled'
  552. noLabel
  553. >
  554. 允许 HTTP 协议图片请求(适用于自部署代理)
  555. </Form.Checkbox>
  556. <Button onClick={submitWorker}>更新Worker设置</Button>
  557. </Form.Section>
  558. </Card>
  559. <Card>
  560. <Form.Section text='支付设置'>
  561. <Text>
  562. (当前仅支持易支付接口,默认使用上方服务器地址作为回调地址!)
  563. </Text>
  564. <Row
  565. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  566. >
  567. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  568. <Form.Input
  569. field='PayAddress'
  570. label='支付地址'
  571. placeholder='例如:https://yourdomain.com'
  572. />
  573. </Col>
  574. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  575. <Form.Input
  576. field='EpayId'
  577. label='易支付商户ID'
  578. placeholder='例如:0001'
  579. />
  580. </Col>
  581. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  582. <Form.Input
  583. field='EpayKey'
  584. label='易支付商户密钥'
  585. placeholder='敏感信息不会发送到前端显示'
  586. type='password'
  587. />
  588. </Col>
  589. </Row>
  590. <Row
  591. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  592. style={{ marginTop: 16 }}
  593. >
  594. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  595. <Form.Input
  596. field='CustomCallbackAddress'
  597. label='回调地址'
  598. placeholder='例如:https://yourdomain.com'
  599. />
  600. </Col>
  601. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  602. <Form.InputNumber
  603. field='Price'
  604. precision={2}
  605. label='充值价格(x元/美金)'
  606. placeholder='例如:7,就是7元/美金'
  607. />
  608. </Col>
  609. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  610. <Form.InputNumber
  611. field='MinTopUp'
  612. label='最低充值美元数量'
  613. placeholder='例如:2,就是最低充值2$'
  614. />
  615. </Col>
  616. </Row>
  617. <Form.TextArea
  618. field='TopupGroupRatio'
  619. label='充值分组倍率'
  620. placeholder='为一个 JSON 文本,键为组名称,值为倍率'
  621. autosize
  622. />
  623. <Form.TextArea
  624. field='PayMethods'
  625. label='充值方式设置'
  626. placeholder='为一个 JSON 文本'
  627. autosize
  628. />
  629. <Button onClick={submitPayAddress}>更新支付设置</Button>
  630. </Form.Section>
  631. </Card>
  632. <Card>
  633. <Form.Section text='配置登录注册'>
  634. <Row
  635. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  636. >
  637. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  638. <Form.Checkbox
  639. field='PasswordLoginEnabled'
  640. noLabel
  641. onChange={(e) =>
  642. handleCheckboxChange('PasswordLoginEnabled', e)
  643. }
  644. >
  645. 允许通过密码进行登录
  646. </Form.Checkbox>
  647. <Form.Checkbox
  648. field='PasswordRegisterEnabled'
  649. noLabel
  650. onChange={(e) =>
  651. handleCheckboxChange('PasswordRegisterEnabled', e)
  652. }
  653. >
  654. 允许通过密码进行注册
  655. </Form.Checkbox>
  656. <Form.Checkbox
  657. field='EmailVerificationEnabled'
  658. noLabel
  659. onChange={(e) =>
  660. handleCheckboxChange('EmailVerificationEnabled', e)
  661. }
  662. >
  663. 通过密码注册时需要进行邮箱验证
  664. </Form.Checkbox>
  665. <Form.Checkbox
  666. field='RegisterEnabled'
  667. noLabel
  668. onChange={(e) =>
  669. handleCheckboxChange('RegisterEnabled', e)
  670. }
  671. >
  672. 允许新用户注册
  673. </Form.Checkbox>
  674. <Form.Checkbox
  675. field='TurnstileCheckEnabled'
  676. noLabel
  677. onChange={(e) =>
  678. handleCheckboxChange('TurnstileCheckEnabled', e)
  679. }
  680. >
  681. 启用 Turnstile 用户校验
  682. </Form.Checkbox>
  683. </Col>
  684. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  685. <Form.Checkbox
  686. field='GitHubOAuthEnabled'
  687. noLabel
  688. onChange={(e) =>
  689. handleCheckboxChange('GitHubOAuthEnabled', e)
  690. }
  691. >
  692. 允许通过 GitHub 账户登录 & 注册
  693. </Form.Checkbox>
  694. <Form.Checkbox
  695. field='LinuxDOOAuthEnabled'
  696. noLabel
  697. onChange={(e) =>
  698. handleCheckboxChange('LinuxDOOAuthEnabled', e)
  699. }
  700. >
  701. 允许通过 Linux DO 账户登录 & 注册
  702. </Form.Checkbox>
  703. <Form.Checkbox
  704. field='WeChatAuthEnabled'
  705. noLabel
  706. onChange={(e) =>
  707. handleCheckboxChange('WeChatAuthEnabled', e)
  708. }
  709. >
  710. 允许通过微信登录 & 注册
  711. </Form.Checkbox>
  712. <Form.Checkbox
  713. field='TelegramOAuthEnabled'
  714. noLabel
  715. onChange={(e) =>
  716. handleCheckboxChange('TelegramOAuthEnabled', e)
  717. }
  718. >
  719. 允许通过 Telegram 进行登录
  720. </Form.Checkbox>
  721. <Form.Checkbox
  722. field="['oidc.enabled']"
  723. noLabel
  724. onChange={(e) =>
  725. handleCheckboxChange('oidc.enabled', e)
  726. }
  727. >
  728. 允许通过 OIDC 进行登录
  729. </Form.Checkbox>
  730. </Col>
  731. </Row>
  732. </Form.Section>
  733. </Card>
  734. <Card>
  735. <Form.Section text='配置邮箱域名白名单'>
  736. <Text>用以防止恶意用户利用临时邮箱批量注册</Text>
  737. <Row
  738. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  739. >
  740. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  741. <Form.Checkbox
  742. field='EmailDomainRestrictionEnabled'
  743. noLabel
  744. onChange={(e) =>
  745. handleCheckboxChange(
  746. 'EmailDomainRestrictionEnabled',
  747. e,
  748. )
  749. }
  750. >
  751. 启用邮箱域名白名单
  752. </Form.Checkbox>
  753. </Col>
  754. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  755. <Form.Checkbox
  756. field='EmailAliasRestrictionEnabled'
  757. noLabel
  758. onChange={(e) =>
  759. handleCheckboxChange(
  760. 'EmailAliasRestrictionEnabled',
  761. e,
  762. )
  763. }
  764. >
  765. 启用邮箱别名限制
  766. </Form.Checkbox>
  767. </Col>
  768. </Row>
  769. <TagInput
  770. value={emailDomainWhitelist}
  771. onChange={setEmailDomainWhitelist}
  772. placeholder='输入域名后回车'
  773. style={{ width: '100%', marginTop: 16 }}
  774. />
  775. <Form.Input
  776. placeholder='输入要添加的邮箱域名'
  777. value={emailToAdd}
  778. onChange={(value) => setEmailToAdd(value)}
  779. style={{ marginTop: 16 }}
  780. suffix={
  781. <Button
  782. theme='solid'
  783. type='primary'
  784. onClick={handleAddEmail}
  785. >
  786. 添加
  787. </Button>
  788. }
  789. onEnterPress={handleAddEmail}
  790. />
  791. <Button
  792. onClick={submitEmailDomainWhitelist}
  793. style={{ marginTop: 10 }}
  794. >
  795. 保存邮箱域名白名单设置
  796. </Button>
  797. </Form.Section>
  798. </Card>
  799. <Card>
  800. <Form.Section text='配置 SMTP'>
  801. <Text>用以支持系统的邮件发送</Text>
  802. <Row
  803. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  804. >
  805. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  806. <Form.Input field='SMTPServer' label='SMTP 服务器地址' />
  807. </Col>
  808. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  809. <Form.Input field='SMTPPort' label='SMTP 端口' />
  810. </Col>
  811. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  812. <Form.Input field='SMTPAccount' label='SMTP 账户' />
  813. </Col>
  814. </Row>
  815. <Row
  816. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  817. style={{ marginTop: 16 }}
  818. >
  819. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  820. <Form.Input field='SMTPFrom' label='SMTP 发送者邮箱' />
  821. </Col>
  822. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  823. <Form.Input
  824. field='SMTPToken'
  825. label='SMTP 访问凭证'
  826. type='password'
  827. placeholder='敏感信息不会发送到前端显示'
  828. />
  829. </Col>
  830. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  831. <Form.Checkbox
  832. field='SMTPSSLEnabled'
  833. noLabel
  834. onChange={(e) =>
  835. handleCheckboxChange('SMTPSSLEnabled', e)
  836. }
  837. >
  838. 启用SMTP SSL
  839. </Form.Checkbox>
  840. </Col>
  841. </Row>
  842. <Button onClick={submitSMTP}>保存 SMTP 设置</Button>
  843. </Form.Section>
  844. </Card>
  845. <Card>
  846. <Form.Section text='配置 OIDC'>
  847. <Text>
  848. 用以支持通过 OIDC 登录,例如 Okta、Auth0 等兼容 OIDC 协议的
  849. IdP
  850. </Text>
  851. <Banner
  852. type='info'
  853. description={`主页链接填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'},重定向 URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'}/oauth/oidc`}
  854. style={{ marginBottom: 20, marginTop: 16 }}
  855. />
  856. <Text>
  857. 若你的 OIDC Provider 支持 Discovery Endpoint,你可以仅填写
  858. OIDC Well-Known URL,系统会自动获取 OIDC 配置
  859. </Text>
  860. <Row
  861. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  862. >
  863. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  864. <Form.Input
  865. field="['oidc.well_known']"
  866. label='Well-Known URL'
  867. placeholder='请输入 OIDC 的 Well-Known URL'
  868. />
  869. </Col>
  870. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  871. <Form.Input
  872. field="['oidc.client_id']"
  873. label='Client ID'
  874. placeholder='输入 OIDC 的 Client ID'
  875. />
  876. </Col>
  877. </Row>
  878. <Row
  879. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  880. >
  881. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  882. <Form.Input
  883. field="['oidc.client_secret']"
  884. label='Client Secret'
  885. type='password'
  886. placeholder='敏感信息不会发送到前端显示'
  887. />
  888. </Col>
  889. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  890. <Form.Input
  891. field="['oidc.authorization_endpoint']"
  892. label='Authorization Endpoint'
  893. placeholder='输入 OIDC 的 Authorization Endpoint'
  894. />
  895. </Col>
  896. </Row>
  897. <Row
  898. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  899. >
  900. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  901. <Form.Input
  902. field="['oidc.token_endpoint']"
  903. label='Token Endpoint'
  904. placeholder='输入 OIDC 的 Token Endpoint'
  905. />
  906. </Col>
  907. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  908. <Form.Input
  909. field="['oidc.user_info_endpoint']"
  910. label='User Info Endpoint'
  911. placeholder='输入 OIDC 的 Userinfo Endpoint'
  912. />
  913. </Col>
  914. </Row>
  915. <Button onClick={submitOIDCSettings}>保存 OIDC 设置</Button>
  916. </Form.Section>
  917. </Card>
  918. <Card>
  919. <Form.Section text='配置 GitHub OAuth App'>
  920. <Text>用以支持通过 GitHub 进行登录注册</Text>
  921. <Banner
  922. type='info'
  923. description={`Homepage URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'},Authorization callback URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'}/oauth/github`}
  924. style={{ marginBottom: 20, marginTop: 16 }}
  925. />
  926. <Row
  927. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  928. >
  929. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  930. <Form.Input
  931. field='GitHubClientId'
  932. label='GitHub Client ID'
  933. />
  934. </Col>
  935. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  936. <Form.Input
  937. field='GitHubClientSecret'
  938. label='GitHub Client Secret'
  939. type='password'
  940. placeholder='敏感信息不会发送到前端显示'
  941. />
  942. </Col>
  943. </Row>
  944. <Button onClick={submitGitHubOAuth}>
  945. 保存 GitHub OAuth 设置
  946. </Button>
  947. </Form.Section>
  948. </Card>
  949. <Card>
  950. <Form.Section text='配置 Linux DO OAuth'>
  951. <Text>
  952. 用以支持通过 Linux DO 进行登录注册
  953. <a
  954. href='https://connect.linux.do/'
  955. target='_blank'
  956. rel='noreferrer'
  957. style={{
  958. display: 'inline-block',
  959. marginLeft: 4,
  960. marginRight: 4,
  961. }}
  962. >
  963. 点击此处
  964. </a>
  965. 管理你的 LinuxDO OAuth App
  966. </Text>
  967. <Banner
  968. type='info'
  969. description={`回调 URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'}/oauth/linuxdo`}
  970. style={{ marginBottom: 20, marginTop: 16 }}
  971. />
  972. <Row
  973. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  974. >
  975. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  976. <Form.Input
  977. field='LinuxDOClientId'
  978. label='Linux DO Client ID'
  979. placeholder='输入你注册的 LinuxDO OAuth APP 的 ID'
  980. />
  981. </Col>
  982. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  983. <Form.Input
  984. field='LinuxDOClientSecret'
  985. label='Linux DO Client Secret'
  986. type='password'
  987. placeholder='敏感信息不会发送到前端显示'
  988. />
  989. </Col>
  990. </Row>
  991. <Button onClick={submitLinuxDOOAuth}>
  992. 保存 Linux DO OAuth 设置
  993. </Button>
  994. </Form.Section>
  995. </Card>
  996. <Card>
  997. <Form.Section text='配置 WeChat Server'>
  998. <Text>用以支持通过微信进行登录注册</Text>
  999. <Row
  1000. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1001. >
  1002. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1003. <Form.Input
  1004. field='WeChatServerAddress'
  1005. label='WeChat Server 服务器地址'
  1006. />
  1007. </Col>
  1008. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1009. <Form.Input
  1010. field='WeChatServerToken'
  1011. label='WeChat Server 访问凭证'
  1012. type='password'
  1013. placeholder='敏感信息不会发送到前端显示'
  1014. />
  1015. </Col>
  1016. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  1017. <Form.Input
  1018. field='WeChatAccountQRCodeImageURL'
  1019. label='微信公众号二维码图片链接'
  1020. />
  1021. </Col>
  1022. </Row>
  1023. <Button onClick={submitWeChat}>
  1024. 保存 WeChat Server 设置
  1025. </Button>
  1026. </Form.Section>
  1027. </Card>
  1028. <Card>
  1029. <Form.Section text='配置 Telegram 登录'>
  1030. <Text>用以支持通过 Telegram 进行登录注册</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='TelegramBotToken'
  1037. label='Telegram Bot Token'
  1038. placeholder='敏感信息不会发送到前端显示'
  1039. type='password'
  1040. />
  1041. </Col>
  1042. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1043. <Form.Input
  1044. field='TelegramBotName'
  1045. label='Telegram Bot 名称'
  1046. />
  1047. </Col>
  1048. </Row>
  1049. <Button onClick={submitTelegramSettings}>
  1050. 保存 Telegram 登录设置
  1051. </Button>
  1052. </Form.Section>
  1053. </Card>
  1054. <Card>
  1055. <Form.Section text='配置 Turnstile'>
  1056. <Text>用以支持用户校验</Text>
  1057. <Row
  1058. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1059. >
  1060. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1061. <Form.Input
  1062. field='TurnstileSiteKey'
  1063. label='Turnstile Site Key'
  1064. />
  1065. </Col>
  1066. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1067. <Form.Input
  1068. field='TurnstileSecretKey'
  1069. label='Turnstile Secret Key'
  1070. type='password'
  1071. placeholder='敏感信息不会发送到前端显示'
  1072. />
  1073. </Col>
  1074. </Row>
  1075. <Button onClick={submitTurnstile}>保存 Turnstile 设置</Button>
  1076. </Form.Section>
  1077. </Card>
  1078. <Modal
  1079. title='确认取消密码登录'
  1080. visible={showPasswordLoginConfirmModal}
  1081. onOk={handlePasswordLoginConfirm}
  1082. onCancel={() => {
  1083. setShowPasswordLoginConfirmModal(false);
  1084. formApiRef.current.setValue('PasswordLoginEnabled', true);
  1085. }}
  1086. okText='确认'
  1087. cancelText='取消'
  1088. >
  1089. <p>您确定要取消密码登录功能吗?这可能会影响用户的登录方式。</p>
  1090. </Modal>
  1091. </div>
  1092. )}
  1093. </Form>
  1094. ) : (
  1095. <div
  1096. style={{
  1097. display: 'flex',
  1098. justifyContent: 'center',
  1099. alignItems: 'center',
  1100. height: '100vh',
  1101. }}
  1102. >
  1103. <Spin size='large' />
  1104. </div>
  1105. )}
  1106. </div>
  1107. );
  1108. };
  1109. export default SystemSetting;