SystemSetting.js 40 KB

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