SystemSetting.js 39 KB

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