SystemSetting.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. import React, { useEffect, useState } from 'react';
  2. import {
  3. Button,
  4. Divider,
  5. Form,
  6. Grid,
  7. Header,
  8. Message,
  9. Modal,
  10. } from 'semantic-ui-react';
  11. import { API, removeTrailingSlash, showError, verifyJSON } from '../helpers';
  12. import { useTheme } from '../context/Theme';
  13. const SystemSetting = () => {
  14. let [inputs, setInputs] = useState({
  15. PasswordLoginEnabled: '',
  16. PasswordRegisterEnabled: '',
  17. EmailVerificationEnabled: '',
  18. GitHubOAuthEnabled: '',
  19. GitHubClientId: '',
  20. GitHubClientSecret: '',
  21. OIDCEnabled: '',
  22. OIDCClientId: '',
  23. OIDCClientSecret: '',
  24. OIDCWellKnown: '',
  25. OIDCAuthorizationEndpoint: '',
  26. OIDCTokenEndpoint: '',
  27. OIDCUserInfoEndpoint: '',
  28. Notice: '',
  29. SMTPServer: '',
  30. SMTPPort: '',
  31. SMTPAccount: '',
  32. SMTPFrom: '',
  33. SMTPToken: '',
  34. ServerAddress: '',
  35. WorkerUrl: '',
  36. WorkerValidKey: '',
  37. EpayId: '',
  38. EpayKey: '',
  39. Price: 7.3,
  40. MinTopUp: 1,
  41. TopupGroupRatio: '',
  42. PayAddress: '',
  43. CustomCallbackAddress: '',
  44. Footer: '',
  45. WeChatAuthEnabled: '',
  46. WeChatServerAddress: '',
  47. WeChatServerToken: '',
  48. WeChatAccountQRCodeImageURL: '',
  49. TurnstileCheckEnabled: '',
  50. TurnstileSiteKey: '',
  51. TurnstileSecretKey: '',
  52. RegisterEnabled: '',
  53. EmailDomainRestrictionEnabled: '',
  54. EmailAliasRestrictionEnabled: '',
  55. SMTPSSLEnabled: '',
  56. EmailDomainWhitelist: [],
  57. // telegram login
  58. TelegramOAuthEnabled: '',
  59. TelegramBotToken: '',
  60. TelegramBotName: '',
  61. LinuxDOOAuthEnabled: '',
  62. LinuxDOClientId: '',
  63. LinuxDOClientSecret: '',
  64. });
  65. const [originInputs, setOriginInputs] = useState({});
  66. let [loading, setLoading] = useState(false);
  67. const [EmailDomainWhitelist, setEmailDomainWhitelist] = useState([]);
  68. const [restrictedDomainInput, setRestrictedDomainInput] = useState('');
  69. const [showPasswordWarningModal, setShowPasswordWarningModal] =
  70. useState(false);
  71. const theme = useTheme();
  72. const isDark = theme === 'dark';
  73. const getOptions = async () => {
  74. const res = await API.get('/api/option/');
  75. const { success, message, data } = res.data;
  76. if (success) {
  77. let newInputs = {};
  78. data.forEach((item) => {
  79. if (item.key === 'TopupGroupRatio') {
  80. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  81. }
  82. newInputs[item.key] = item.value;
  83. });
  84. setInputs({
  85. ...newInputs,
  86. EmailDomainWhitelist: newInputs.EmailDomainWhitelist.split(','),
  87. });
  88. setOriginInputs(newInputs);
  89. setEmailDomainWhitelist(
  90. newInputs.EmailDomainWhitelist.split(',').map((item) => {
  91. return { key: item, text: item, value: item };
  92. }),
  93. );
  94. } else {
  95. showError(message);
  96. }
  97. };
  98. useEffect(() => {
  99. getOptions().then();
  100. }, []);
  101. useEffect(() => {}, [inputs.EmailDomainWhitelist]);
  102. const updateOption = async (key, value) => {
  103. setLoading(true);
  104. switch (key) {
  105. case 'PasswordLoginEnabled':
  106. case 'PasswordRegisterEnabled':
  107. case 'EmailVerificationEnabled':
  108. case 'GitHubOAuthEnabled':
  109. case 'OIDCEnabled':
  110. case 'LinuxDOOAuthEnabled':
  111. case 'WeChatAuthEnabled':
  112. case 'TelegramOAuthEnabled':
  113. case 'TurnstileCheckEnabled':
  114. case 'EmailDomainRestrictionEnabled':
  115. case 'EmailAliasRestrictionEnabled':
  116. case 'SMTPSSLEnabled':
  117. case 'RegisterEnabled':
  118. value = inputs[key] === 'true' ? 'false' : 'true';
  119. break;
  120. default:
  121. break;
  122. }
  123. const res = await API.put('/api/option/', {
  124. key,
  125. value,
  126. });
  127. const { success, message } = res.data;
  128. if (success) {
  129. if (key === 'EmailDomainWhitelist') {
  130. value = value.split(',');
  131. }
  132. if (key === 'Price') {
  133. value = parseFloat(value);
  134. }
  135. setInputs((inputs) => ({
  136. ...inputs,
  137. [key]: value,
  138. }));
  139. } else {
  140. showError(message);
  141. }
  142. setLoading(false);
  143. };
  144. const handleInputChange = async (e, { name, value }) => {
  145. if (name === 'PasswordLoginEnabled' && inputs[name] === 'true') {
  146. // block disabling password login
  147. setShowPasswordWarningModal(true);
  148. return;
  149. }
  150. if (
  151. name === 'Notice' ||
  152. (name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') ||
  153. name === 'ServerAddress' ||
  154. name === 'WorkerUrl' ||
  155. name === 'WorkerValidKey' ||
  156. name === 'EpayId' ||
  157. name === 'EpayKey' ||
  158. name === 'Price' ||
  159. name === 'PayAddress' ||
  160. name === 'GitHubClientId' ||
  161. name === 'GitHubClientSecret' ||
  162. name === 'OIDCWellKnown' ||
  163. name === 'OIDCClientId' ||
  164. name === 'OIDCClientSecret' ||
  165. name === 'OIDCAuthorizationEndpoint' ||
  166. name === 'OIDCTokenEndpoint' ||
  167. name === 'OIDCUserInfoEndpoint' ||
  168. name === 'WeChatServerAddress' ||
  169. name === 'WeChatServerToken' ||
  170. name === 'WeChatAccountQRCodeImageURL' ||
  171. name === 'TurnstileSiteKey' ||
  172. name === 'TurnstileSecretKey' ||
  173. name === 'EmailDomainWhitelist' ||
  174. name === 'TopupGroupRatio' ||
  175. name === 'TelegramBotToken' ||
  176. name === 'TelegramBotName' ||
  177. name === 'LinuxDOClientId' ||
  178. name === 'LinuxDOClientSecret'
  179. ) {
  180. setInputs((inputs) => ({ ...inputs, [name]: value }));
  181. } else {
  182. await updateOption(name, value);
  183. }
  184. };
  185. const submitServerAddress = async () => {
  186. let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
  187. await updateOption('ServerAddress', ServerAddress);
  188. };
  189. const submitWorker = async () => {
  190. let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
  191. await updateOption('WorkerUrl', WorkerUrl);
  192. if (inputs.WorkerValidKey !== '') {
  193. await updateOption('WorkerValidKey', inputs.WorkerValidKey);
  194. }
  195. };
  196. const submitPayAddress = async () => {
  197. if (inputs.ServerAddress === '') {
  198. showError('请先填写服务器地址');
  199. return;
  200. }
  201. if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
  202. if (!verifyJSON(inputs.TopupGroupRatio)) {
  203. showError('充值分组倍率不是合法的 JSON 字符串');
  204. return;
  205. }
  206. await updateOption('TopupGroupRatio', inputs.TopupGroupRatio);
  207. }
  208. let PayAddress = removeTrailingSlash(inputs.PayAddress);
  209. await updateOption('PayAddress', PayAddress);
  210. if (inputs.EpayId !== '') {
  211. await updateOption('EpayId', inputs.EpayId);
  212. }
  213. if (inputs.EpayKey !== undefined && inputs.EpayKey !== '') {
  214. await updateOption('EpayKey', inputs.EpayKey);
  215. }
  216. await updateOption('Price', '' + inputs.Price);
  217. };
  218. const submitSMTP = async () => {
  219. if (originInputs['SMTPServer'] !== inputs.SMTPServer) {
  220. await updateOption('SMTPServer', inputs.SMTPServer);
  221. }
  222. if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
  223. await updateOption('SMTPAccount', inputs.SMTPAccount);
  224. }
  225. if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) {
  226. await updateOption('SMTPFrom', inputs.SMTPFrom);
  227. }
  228. if (
  229. originInputs['SMTPPort'] !== inputs.SMTPPort &&
  230. inputs.SMTPPort !== ''
  231. ) {
  232. await updateOption('SMTPPort', inputs.SMTPPort);
  233. }
  234. if (
  235. originInputs['SMTPToken'] !== inputs.SMTPToken &&
  236. inputs.SMTPToken !== ''
  237. ) {
  238. await updateOption('SMTPToken', inputs.SMTPToken);
  239. }
  240. };
  241. const submitEmailDomainWhitelist = async () => {
  242. if (
  243. originInputs['EmailDomainWhitelist'] !==
  244. inputs.EmailDomainWhitelist.join(',') &&
  245. inputs.SMTPToken !== ''
  246. ) {
  247. await updateOption(
  248. 'EmailDomainWhitelist',
  249. inputs.EmailDomainWhitelist.join(','),
  250. );
  251. }
  252. };
  253. const submitWeChat = async () => {
  254. if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
  255. await updateOption(
  256. 'WeChatServerAddress',
  257. removeTrailingSlash(inputs.WeChatServerAddress),
  258. );
  259. }
  260. if (
  261. originInputs['WeChatAccountQRCodeImageURL'] !==
  262. inputs.WeChatAccountQRCodeImageURL
  263. ) {
  264. await updateOption(
  265. 'WeChatAccountQRCodeImageURL',
  266. inputs.WeChatAccountQRCodeImageURL,
  267. );
  268. }
  269. if (
  270. originInputs['WeChatServerToken'] !== inputs.WeChatServerToken &&
  271. inputs.WeChatServerToken !== ''
  272. ) {
  273. await updateOption('WeChatServerToken', inputs.WeChatServerToken);
  274. }
  275. };
  276. const submitGitHubOAuth = async () => {
  277. if (originInputs['GitHubClientId'] !== inputs.GitHubClientId) {
  278. await updateOption('GitHubClientId', inputs.GitHubClientId);
  279. }
  280. if (
  281. originInputs['GitHubClientSecret'] !== inputs.GitHubClientSecret &&
  282. inputs.GitHubClientSecret !== ''
  283. ) {
  284. await updateOption('GitHubClientSecret', inputs.GitHubClientSecret);
  285. }
  286. };
  287. const submitOIDCSettings = async () => {
  288. if (inputs.OIDCWellKnown !== '') {
  289. if (!inputs.OIDCWellKnown.startsWith('http://') && !inputs.OIDCWellKnown.startsWith('https://')) {
  290. showError('Well-Known URL 必须以 http:// 或 https:// 开头');
  291. return;
  292. }
  293. try {
  294. const res = await API.get(inputs.OIDCWellKnown);
  295. inputs.OIDCAuthorizationEndpoint = res.data['authorization_endpoint'];
  296. inputs.OIDCTokenEndpoint = res.data['token_endpoint'];
  297. inputs.OIDCUserInfoEndpoint = res.data['userinfo_endpoint'];
  298. showSuccess('获取 OIDC 配置成功!');
  299. } catch (err) {
  300. showError("获取 OIDC 配置失败,请检查网络状况和 Well-Known URL 是否正确");
  301. }
  302. }
  303. if (originInputs['OIDCWellKnown'] !== inputs.OIDCWellKnown) {
  304. await updateOption('OIDCWellKnown', inputs.OIDCWellKnown);
  305. }
  306. if (originInputs['OIDCClientId'] !== inputs.OIDCClientId) {
  307. await updateOption('OIDCClientId', inputs.OIDCClientId);
  308. }
  309. if (originInputs['OIDCClientSecret'] !== inputs.OIDCClientSecret && inputs.OIDCClientSecret !== '') {
  310. await updateOption('OIDCClientSecret', inputs.OIDCClientSecret);
  311. }
  312. if (originInputs['OIDCAuthorizationEndpoint'] !== inputs.OIDCAuthorizationEndpoint) {
  313. await updateOption('OIDCAuthorizationEndpoint', inputs.OIDCAuthorizationEndpoint);
  314. }
  315. if (originInputs['OIDCTokenEndpoint'] !== inputs.OIDCTokenEndpoint) {
  316. await updateOption('OIDCTokenEndpoint', inputs.OIDCTokenEndpoint);
  317. }
  318. if (originInputs['OIDCUserInfoEndpoint'] !== inputs.OIDCUserInfoEndpoint) {
  319. await updateOption('OIDCUserInfoEndpoint', inputs.OIDCUserInfoEndpoint);
  320. }
  321. }
  322. const submitTelegramSettings = async () => {
  323. // await updateOption('TelegramOAuthEnabled', inputs.TelegramOAuthEnabled);
  324. await updateOption('TelegramBotToken', inputs.TelegramBotToken);
  325. await updateOption('TelegramBotName', inputs.TelegramBotName);
  326. };
  327. const submitTurnstile = async () => {
  328. if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
  329. await updateOption('TurnstileSiteKey', inputs.TurnstileSiteKey);
  330. }
  331. if (
  332. originInputs['TurnstileSecretKey'] !== inputs.TurnstileSecretKey &&
  333. inputs.TurnstileSecretKey !== ''
  334. ) {
  335. await updateOption('TurnstileSecretKey', inputs.TurnstileSecretKey);
  336. }
  337. };
  338. const submitNewRestrictedDomain = () => {
  339. const localDomainList = inputs.EmailDomainWhitelist;
  340. if (
  341. restrictedDomainInput !== '' &&
  342. !localDomainList.includes(restrictedDomainInput)
  343. ) {
  344. setRestrictedDomainInput('');
  345. setInputs({
  346. ...inputs,
  347. EmailDomainWhitelist: [...localDomainList, restrictedDomainInput],
  348. });
  349. setEmailDomainWhitelist([
  350. ...EmailDomainWhitelist,
  351. {
  352. key: restrictedDomainInput,
  353. text: restrictedDomainInput,
  354. value: restrictedDomainInput,
  355. },
  356. ]);
  357. }
  358. };
  359. const submitLinuxDOOAuth = async () => {
  360. if (originInputs['LinuxDOClientId'] !== inputs.LinuxDOClientId) {
  361. await updateOption('LinuxDOClientId', inputs.LinuxDOClientId);
  362. }
  363. if (
  364. originInputs['LinuxDOClientSecret'] !== inputs.LinuxDOClientSecret &&
  365. inputs.LinuxDOClientSecret !== ''
  366. ) {
  367. await updateOption('LinuxDOClientSecret', inputs.LinuxDOClientSecret);
  368. }
  369. };
  370. return (
  371. <Grid columns={1}>
  372. <Grid.Column>
  373. <Form loading={loading} inverted={isDark}>
  374. <Header as='h3' inverted={isDark}>
  375. 通用设置
  376. </Header>
  377. <Form.Group widths='equal'>
  378. <Form.Input
  379. label='服务器地址'
  380. placeholder='例如:https://yourdomain.com'
  381. value={inputs.ServerAddress}
  382. name='ServerAddress'
  383. onChange={handleInputChange}
  384. />
  385. </Form.Group>
  386. <Form.Button onClick={submitServerAddress}>
  387. 更新服务器地址
  388. </Form.Button>
  389. <Header as='h3' inverted={isDark}>
  390. 代理设置(支持{' '}
  391. <a
  392. href='https://github.com/Calcium-Ion/new-api-worker'
  393. target='_blank'
  394. rel='noreferrer'
  395. >
  396. new-api-worker
  397. </a>
  398. </Header>
  399. <Message info>
  400. 注意:代理功能仅对图片请求和 Webhook 请求生效,不会影响其他 API 请求。如需配置 API 请求代理,请参考
  401. <a
  402. href='https://github.com/Calcium-Ion/new-api/blob/main/docs/channel/other_setting.md'
  403. target='_blank'
  404. rel='noreferrer'
  405. >
  406. {' '}API 代理设置文档
  407. </a>
  408. </Message>
  409. <Form.Group widths='equal'>
  410. <Form.Input
  411. label='Worker地址,不填写则不启用代理'
  412. placeholder='例如:https://workername.yourdomain.workers.dev'
  413. value={inputs.WorkerUrl}
  414. name='WorkerUrl'
  415. onChange={handleInputChange}
  416. />
  417. <Form.Input
  418. label='Worker密钥,根据你部署的 Worker 填写'
  419. placeholder='例如:your_secret_key'
  420. value={inputs.WorkerValidKey}
  421. name='WorkerValidKey'
  422. onChange={handleInputChange}
  423. />
  424. </Form.Group>
  425. <Form.Button onClick={submitWorker}>更新Worker设置</Form.Button>
  426. <Divider />
  427. <Header as='h3' inverted={isDark}>
  428. 支付设置(当前仅支持易支付接口,默认使用上方服务器地址作为回调地址!)
  429. </Header>
  430. <Form.Group widths='equal'>
  431. <Form.Input
  432. label='支付地址,不填写则不启用在线支付'
  433. placeholder='例如:https://yourdomain.com'
  434. value={inputs.PayAddress}
  435. name='PayAddress'
  436. onChange={handleInputChange}
  437. />
  438. <Form.Input
  439. label='易支付商户ID'
  440. placeholder='例如:0001'
  441. value={inputs.EpayId}
  442. name='EpayId'
  443. onChange={handleInputChange}
  444. />
  445. <Form.Input
  446. label='易支付商户密钥'
  447. placeholder='敏感信息不会发送到前端显示'
  448. value={inputs.EpayKey}
  449. name='EpayKey'
  450. onChange={handleInputChange}
  451. />
  452. </Form.Group>
  453. <Form.Group widths='equal'>
  454. <Form.Input
  455. label='回调地址,不填写则使用上方服务器地址作为回调地址'
  456. placeholder='例如:https://yourdomain.com'
  457. value={inputs.CustomCallbackAddress}
  458. name='CustomCallbackAddress'
  459. onChange={handleInputChange}
  460. />
  461. <Form.Input
  462. label='充值价格(x元/美金)'
  463. placeholder='例如:7,就是7元/美金'
  464. value={inputs.Price}
  465. name='Price'
  466. min={0}
  467. onChange={handleInputChange}
  468. />
  469. <Form.Input
  470. label='最低充值美元数量(以美金为单位,如果使用额度请自行换算!)'
  471. placeholder='例如:2,就是最低充值2$'
  472. value={inputs.MinTopUp}
  473. name='MinTopUp'
  474. min={1}
  475. onChange={handleInputChange}
  476. />
  477. </Form.Group>
  478. <Form.Group widths='equal'>
  479. <Form.TextArea
  480. label='充值分组倍率'
  481. name='TopupGroupRatio'
  482. onChange={handleInputChange}
  483. style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
  484. autoComplete='new-password'
  485. value={inputs.TopupGroupRatio}
  486. placeholder='为一个 JSON 文本,键为组名称,值为倍率'
  487. />
  488. </Form.Group>
  489. <Form.Button onClick={submitPayAddress}>更新支付设置</Form.Button>
  490. <Divider />
  491. <Header as='h3' inverted={isDark}>
  492. 配置登录注册
  493. </Header>
  494. <Form.Group inline>
  495. <Form.Checkbox
  496. checked={inputs.PasswordLoginEnabled === 'true'}
  497. label='允许通过密码进行登录'
  498. name='PasswordLoginEnabled'
  499. onChange={handleInputChange}
  500. />
  501. {showPasswordWarningModal && (
  502. <Modal
  503. open={showPasswordWarningModal}
  504. onClose={() => setShowPasswordWarningModal(false)}
  505. size={'tiny'}
  506. style={{ maxWidth: '450px' }}
  507. >
  508. <Modal.Header>警告</Modal.Header>
  509. <Modal.Content>
  510. <p>
  511. 取消密码登录将导致所有未绑定其他登录方式的用户(包括管理员)无法通过密码登录,确认取消?
  512. </p>
  513. </Modal.Content>
  514. <Modal.Actions>
  515. <Button onClick={() => setShowPasswordWarningModal(false)}>
  516. 取消
  517. </Button>
  518. <Button
  519. color='yellow'
  520. onClick={async () => {
  521. setShowPasswordWarningModal(false);
  522. await updateOption('PasswordLoginEnabled', 'false');
  523. }}
  524. >
  525. 确定
  526. </Button>
  527. </Modal.Actions>
  528. </Modal>
  529. )}
  530. <Form.Checkbox
  531. checked={inputs.PasswordRegisterEnabled === 'true'}
  532. label='允许通过密码进行注册'
  533. name='PasswordRegisterEnabled'
  534. onChange={handleInputChange}
  535. />
  536. <Form.Checkbox
  537. checked={inputs.EmailVerificationEnabled === 'true'}
  538. label='通过密码注册时需要进行邮箱验证'
  539. name='EmailVerificationEnabled'
  540. onChange={handleInputChange}
  541. />
  542. <Form.Checkbox
  543. checked={inputs.GitHubOAuthEnabled === 'true'}
  544. label='允许通过 GitHub 账户登录 & 注册'
  545. name='GitHubOAuthEnabled'
  546. onChange={handleInputChange}
  547. />
  548. <Form.Checkbox
  549. checked={inputs.OIDCEnabled === 'true'}
  550. label='允许通过 OIDC 登录 & 注册'
  551. name='OIDCEnabled'
  552. onChange={handleInputChange}
  553. />
  554. <Form.Checkbox
  555. checked={inputs.LinuxDOOAuthEnabled === 'true'}
  556. label='允许通过 LinuxDO 账户登录 & 注册'
  557. name='LinuxDOOAuthEnabled'
  558. onChange={handleInputChange}
  559. />
  560. <Form.Checkbox
  561. checked={inputs.WeChatAuthEnabled === 'true'}
  562. label='允许通过微信登录 & 注册'
  563. name='WeChatAuthEnabled'
  564. onChange={handleInputChange}
  565. />
  566. <Form.Checkbox
  567. checked={inputs.TelegramOAuthEnabled === 'true'}
  568. label='允许通过 Telegram 进行登录'
  569. name='TelegramOAuthEnabled'
  570. onChange={handleInputChange}
  571. />
  572. </Form.Group>
  573. <Form.Group inline>
  574. <Form.Checkbox
  575. checked={inputs.RegisterEnabled === 'true'}
  576. label='允许新用户注册(此项为否时,新用户将无法以任何方式进行注册)'
  577. name='RegisterEnabled'
  578. onChange={handleInputChange}
  579. />
  580. <Form.Checkbox
  581. checked={inputs.TurnstileCheckEnabled === 'true'}
  582. label='启用 Turnstile 用户校验'
  583. name='TurnstileCheckEnabled'
  584. onChange={handleInputChange}
  585. />
  586. </Form.Group>
  587. <Divider />
  588. <Header as='h3' inverted={isDark}>
  589. 配置邮箱域名白名单
  590. <Header.Subheader>
  591. 用以防止恶意用户利用临时邮箱批量注册
  592. </Header.Subheader>
  593. </Header>
  594. <Form.Group widths={3}>
  595. <Form.Checkbox
  596. label='启用邮箱域名白名单'
  597. name='EmailDomainRestrictionEnabled'
  598. onChange={handleInputChange}
  599. checked={inputs.EmailDomainRestrictionEnabled === 'true'}
  600. />
  601. </Form.Group>
  602. <Form.Group widths={3}>
  603. <Form.Checkbox
  604. label='启用邮箱别名限制(例如:ab.cd@gmail.com)'
  605. name='EmailAliasRestrictionEnabled'
  606. onChange={handleInputChange}
  607. checked={inputs.EmailAliasRestrictionEnabled === 'true'}
  608. />
  609. </Form.Group>
  610. <Form.Group widths={2}>
  611. <Form.Dropdown
  612. label='允许的邮箱域名'
  613. placeholder='允许的邮箱域名'
  614. name='EmailDomainWhitelist'
  615. required
  616. fluid
  617. multiple
  618. selection
  619. onChange={handleInputChange}
  620. value={inputs.EmailDomainWhitelist}
  621. autoComplete='new-password'
  622. options={EmailDomainWhitelist}
  623. />
  624. <Form.Input
  625. label='添加新的允许的邮箱域名'
  626. action={
  627. <Button
  628. type='button'
  629. onClick={() => {
  630. submitNewRestrictedDomain();
  631. }}
  632. >
  633. 填入
  634. </Button>
  635. }
  636. onKeyDown={(e) => {
  637. if (e.key === 'Enter') {
  638. submitNewRestrictedDomain();
  639. }
  640. }}
  641. autoComplete='new-password'
  642. placeholder='输入新的允许的邮箱域名'
  643. value={restrictedDomainInput}
  644. onChange={(e, { value }) => {
  645. setRestrictedDomainInput(value);
  646. }}
  647. />
  648. </Form.Group>
  649. <Form.Button onClick={submitEmailDomainWhitelist}>
  650. 保存邮箱域名白名单设置
  651. </Form.Button>
  652. <Divider />
  653. <Header as='h3' inverted={isDark}>
  654. 配置 SMTP
  655. <Header.Subheader>用以支持系统的邮件发送</Header.Subheader>
  656. </Header>
  657. <Form.Group widths={3}>
  658. <Form.Input
  659. label='SMTP 服务器地址'
  660. name='SMTPServer'
  661. onChange={handleInputChange}
  662. autoComplete='new-password'
  663. value={inputs.SMTPServer}
  664. placeholder='例如:smtp.qq.com'
  665. />
  666. <Form.Input
  667. label='SMTP 端口'
  668. name='SMTPPort'
  669. onChange={handleInputChange}
  670. autoComplete='new-password'
  671. value={inputs.SMTPPort}
  672. placeholder='默认: 587'
  673. />
  674. <Form.Input
  675. label='SMTP 账户'
  676. name='SMTPAccount'
  677. onChange={handleInputChange}
  678. autoComplete='new-password'
  679. value={inputs.SMTPAccount}
  680. placeholder='通常是邮箱地址'
  681. />
  682. </Form.Group>
  683. <Form.Group widths={3}>
  684. <Form.Input
  685. label='SMTP 发送者邮箱'
  686. name='SMTPFrom'
  687. onChange={handleInputChange}
  688. autoComplete='new-password'
  689. value={inputs.SMTPFrom}
  690. placeholder='通常和邮箱地址保持一致'
  691. />
  692. <Form.Input
  693. label='SMTP 访问凭证'
  694. name='SMTPToken'
  695. onChange={handleInputChange}
  696. type='password'
  697. autoComplete='new-password'
  698. checked={inputs.RegisterEnabled === 'true'}
  699. placeholder='敏感信息不会发送到前端显示'
  700. />
  701. </Form.Group>
  702. <Form.Group widths={3}>
  703. <Form.Checkbox
  704. label='启用SMTP SSL(465端口强制开启)'
  705. name='SMTPSSLEnabled'
  706. onChange={handleInputChange}
  707. checked={inputs.SMTPSSLEnabled === 'true'}
  708. />
  709. </Form.Group>
  710. <Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
  711. <Divider />
  712. <Header as='h3' inverted={isDark}>
  713. 配置 GitHub OAuth App
  714. <Header.Subheader>
  715. 用以支持通过 GitHub 进行登录注册,
  716. <a
  717. href='https://github.com/settings/developers'
  718. target='_blank'
  719. rel='noreferrer'
  720. >
  721. 点击此处
  722. </a>
  723. 管理你的 GitHub OAuth App
  724. </Header.Subheader>
  725. </Header>
  726. <Message>
  727. Homepage URL 填 <code>{inputs.ServerAddress}</code>
  728. ,Authorization callback URL 填{' '}
  729. <code>{`${inputs.ServerAddress}/oauth/github`}</code>
  730. </Message>
  731. <Form.Group widths={3}>
  732. <Form.Input
  733. label='GitHub Client ID'
  734. name='GitHubClientId'
  735. onChange={handleInputChange}
  736. autoComplete='new-password'
  737. value={inputs.GitHubClientId}
  738. placeholder='输入你注册的 GitHub OAuth APP 的 ID'
  739. />
  740. <Form.Input
  741. label='GitHub Client Secret'
  742. name='GitHubClientSecret'
  743. onChange={handleInputChange}
  744. type='password'
  745. autoComplete='new-password'
  746. value={inputs.GitHubClientSecret}
  747. placeholder='敏感信息不会发送到前端显示'
  748. />
  749. </Form.Group>
  750. <Form.Button onClick={submitGitHubOAuth}>
  751. 保存 GitHub OAuth 设置
  752. </Form.Button>
  753. <Divider />
  754. <Header as='h3' inverted={isDark}>
  755. 配置 WeChat Server
  756. <Header.Subheader>
  757. 用以支持通过微信进行登录注册,
  758. <a
  759. href='https://github.com/songquanpeng/wechat-server'
  760. target='_blank'
  761. rel='noreferrer'
  762. >
  763. 点击此处
  764. </a>
  765. 了解 WeChat Server
  766. </Header.Subheader>
  767. </Header>
  768. <Form.Group widths={3}>
  769. <Form.Input
  770. label='WeChat Server 服务器地址'
  771. name='WeChatServerAddress'
  772. placeholder='例如:https://yourdomain.com'
  773. onChange={handleInputChange}
  774. autoComplete='new-password'
  775. value={inputs.WeChatServerAddress}
  776. />
  777. <Form.Input
  778. label='WeChat Server 访问凭证'
  779. name='WeChatServerToken'
  780. type='password'
  781. onChange={handleInputChange}
  782. autoComplete='new-password'
  783. value={inputs.WeChatServerToken}
  784. placeholder='敏感信息不会发送到前端显示'
  785. />
  786. <Form.Input
  787. label='微信公众号二维码图片链接'
  788. name='WeChatAccountQRCodeImageURL'
  789. onChange={handleInputChange}
  790. autoComplete='new-password'
  791. value={inputs.WeChatAccountQRCodeImageURL}
  792. placeholder='输入一个图片链接'
  793. />
  794. </Form.Group>
  795. <Form.Button onClick={submitWeChat}>
  796. 保存 WeChat Server 设置
  797. </Form.Button>
  798. <Divider />
  799. <Header as='h3' inverted={isDark}>
  800. 配置 Telegram 登录
  801. </Header>
  802. <Form.Group inline>
  803. <Form.Input
  804. label='Telegram Bot Token'
  805. name='TelegramBotToken'
  806. onChange={handleInputChange}
  807. value={inputs.TelegramBotToken}
  808. placeholder='输入你的 Telegram Bot Token'
  809. />
  810. <Form.Input
  811. label='Telegram Bot 名称'
  812. name='TelegramBotName'
  813. onChange={handleInputChange}
  814. value={inputs.TelegramBotName}
  815. placeholder='输入你的 Telegram Bot 名称'
  816. />
  817. </Form.Group>
  818. <Form.Button onClick={submitTelegramSettings}>
  819. 保存 Telegram 登录设置
  820. </Form.Button>
  821. <Divider />
  822. <Header as='h3' inverted={isDark}>
  823. 配置 Turnstile
  824. <Header.Subheader>
  825. 用以支持用户校验,
  826. <a
  827. href='https://dash.cloudflare.com/'
  828. target='_blank'
  829. rel='noreferrer'
  830. >
  831. 点击此处
  832. </a>
  833. 管理你的 Turnstile Sites,推荐选择 Invisible Widget Type
  834. </Header.Subheader>
  835. </Header>
  836. <Form.Group widths={3}>
  837. <Form.Input
  838. label='Turnstile Site Key'
  839. name='TurnstileSiteKey'
  840. onChange={handleInputChange}
  841. autoComplete='new-password'
  842. value={inputs.TurnstileSiteKey}
  843. placeholder='输入你注册的 Turnstile Site Key'
  844. />
  845. <Form.Input
  846. label='Turnstile Secret Key'
  847. name='TurnstileSecretKey'
  848. onChange={handleInputChange}
  849. type='password'
  850. autoComplete='new-password'
  851. value={inputs.TurnstileSecretKey}
  852. placeholder='敏感信息不会发送到前端显示'
  853. />
  854. </Form.Group>
  855. <Form.Button onClick={submitTurnstile}>
  856. 保存 Turnstile 设置
  857. </Form.Button>
  858. <Divider />
  859. <Header as='h3' inverted={isDark}>
  860. 配置 LinuxDO OAuth App
  861. <Header.Subheader>
  862. 用以支持通过 LinuxDO 进行登录注册,
  863. <a
  864. href='https://connect.linux.do/'
  865. target='_blank'
  866. rel='noreferrer'
  867. >
  868. 点击此处
  869. </a>
  870. 管理你的 LinuxDO OAuth App
  871. </Header.Subheader>
  872. </Header>
  873. <Message>
  874. Homepage URL 填 <code>{inputs.ServerAddress}</code>
  875. ,Authorization callback URL 填{' '}
  876. <code>{`${inputs.ServerAddress}/oauth/linuxdo`}</code>
  877. </Message>
  878. <Form.Group widths={3}>
  879. <Form.Input
  880. label='LinuxDO Client ID'
  881. name='LinuxDOClientId'
  882. onChange={handleInputChange}
  883. autoComplete='new-password'
  884. value={inputs.LinuxDOClientId}
  885. placeholder='输入你注册的 LinuxDO OAuth APP 的 ID'
  886. />
  887. <Form.Input
  888. label='LinuxDO Client Secret'
  889. name='LinuxDOClientSecret'
  890. onChange={handleInputChange}
  891. type='password'
  892. autoComplete='new-password'
  893. value={inputs.LinuxDOClientSecret}
  894. placeholder='敏感信息不会发送到前端显示'
  895. />
  896. </Form.Group>
  897. <Form.Button onClick={submitLinuxDOOAuth}>
  898. 保存 LinuxDO OAuth 设置
  899. </Form.Button>
  900. <Divider />
  901. <Header as='h3' inverted={isDark}>
  902. 配置 OIDC
  903. <Header.Subheader>
  904. 用以支持通过 OIDC 登录,例如 Okta、Auth0 等兼容 OIDC 协议的 IdP
  905. </Header.Subheader>
  906. </Header>
  907. <Message>
  908. 主页链接填 <code>{ inputs.ServerAddress }</code>,
  909. 重定向 URL 填 <code>{ `${ inputs.ServerAddress }/oauth/oidc` }</code>
  910. </Message>
  911. <Message>
  912. 若你的 OIDC Provider 支持 Discovery Endpoint,你可以仅填写 OIDC Well-Known URL,系统会自动获取 OIDC 配置
  913. </Message>
  914. <Form.Group widths={3}>
  915. <Form.Input
  916. label='Client ID'
  917. name='OIDCClientId'
  918. onChange={handleInputChange}
  919. value={inputs.OIDCClientId}
  920. placeholder='输入 OIDC 的 Client ID'
  921. />
  922. <Form.Input
  923. label='Client Secret'
  924. name='OIDCClientSecret'
  925. onChange={handleInputChange}
  926. type='password'
  927. value={inputs.OIDCClientSecret}
  928. placeholder='敏感信息不会发送到前端显示'
  929. />
  930. <Form.Input
  931. label='Well-Known URL'
  932. name='OIDCWellKnown'
  933. onChange={handleInputChange}
  934. value={inputs.OIDCWellKnown}
  935. placeholder='请输入 OIDC 的 Well-Known URL'
  936. />
  937. <Form.Input
  938. label='Authorization Endpoint'
  939. name='OIDCAuthorizationEndpoint'
  940. onChange={handleInputChange}
  941. value={inputs.OIDCAuthorizationEndpoint}
  942. placeholder='输入 OIDC 的 Authorization Endpoint'
  943. />
  944. <Form.Input
  945. label='Token Endpoint'
  946. name='OIDCTokenEndpoint'
  947. onChange={handleInputChange}
  948. value={inputs.OIDCTokenEndpoint}
  949. placeholder='输入 OIDC 的 Token Endpoint'
  950. />
  951. <Form.Input
  952. label='Userinfo Endpoint'
  953. name='OIDCUserInfoEndpoint'
  954. onChange={handleInputChange}
  955. value={inputs.OIDCUserInfoEndpoint}
  956. placeholder='输入 OIDC 的 Userinfo Endpoint'
  957. />
  958. </Form.Group>
  959. <Form.Button onClick={submitOIDCSettings}>
  960. 保存 OIDC 设置
  961. </Form.Button>
  962. </Form>
  963. </Grid.Column>
  964. </Grid>
  965. );
  966. };
  967. export default SystemSetting;