General.svelte 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <script lang="ts">
  2. import { getBackendConfig, getVersionUpdates, getWebhookUrl, updateWebhookUrl } from '$lib/apis';
  3. import {
  4. getAdminConfig,
  5. getLdapConfig,
  6. getLdapServer,
  7. updateAdminConfig,
  8. updateLdapConfig,
  9. updateLdapServer
  10. } from '$lib/apis/auths';
  11. import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
  12. import Switch from '$lib/components/common/Switch.svelte';
  13. import Tooltip from '$lib/components/common/Tooltip.svelte';
  14. import { WEBUI_BUILD_HASH, WEBUI_VERSION } from '$lib/constants';
  15. import { config, showChangelog } from '$lib/stores';
  16. import { compareVersion } from '$lib/utils';
  17. import { onMount, getContext } from 'svelte';
  18. import { toast } from 'svelte-sonner';
  19. const i18n = getContext('i18n');
  20. export let saveHandler: Function;
  21. let updateAvailable = null;
  22. let version = {
  23. current: '',
  24. latest: ''
  25. };
  26. let adminConfig = null;
  27. let webhookUrl = '';
  28. // LDAP
  29. let ENABLE_LDAP = false;
  30. let LDAP_SERVER = {
  31. label: '',
  32. host: '',
  33. port: '',
  34. attribute_for_mail: 'mail',
  35. attribute_for_username: 'uid',
  36. app_dn: '',
  37. app_dn_password: '',
  38. search_base: '',
  39. search_filters: '',
  40. use_tls: false,
  41. certificate_path: '',
  42. ciphers: ''
  43. };
  44. const checkForVersionUpdates = async () => {
  45. updateAvailable = null;
  46. version = await getVersionUpdates(localStorage.token).catch((error) => {
  47. return {
  48. current: WEBUI_VERSION,
  49. latest: WEBUI_VERSION
  50. };
  51. });
  52. console.log(version);
  53. updateAvailable = compareVersion(version.latest, version.current);
  54. console.log(updateAvailable);
  55. };
  56. const updateLdapServerHandler = async () => {
  57. if (!ENABLE_LDAP) return;
  58. const res = await updateLdapServer(localStorage.token, LDAP_SERVER).catch((error) => {
  59. toast.error(`${error}`);
  60. return null;
  61. });
  62. if (res) {
  63. toast.success($i18n.t('LDAP server updated'));
  64. }
  65. };
  66. const updateHandler = async () => {
  67. webhookUrl = await updateWebhookUrl(localStorage.token, webhookUrl);
  68. const res = await updateAdminConfig(localStorage.token, adminConfig);
  69. await updateLdapServerHandler();
  70. if (res) {
  71. saveHandler();
  72. } else {
  73. toast.error(i18n.t('Failed to update settings'));
  74. }
  75. };
  76. onMount(async () => {
  77. checkForVersionUpdates();
  78. await Promise.all([
  79. (async () => {
  80. adminConfig = await getAdminConfig(localStorage.token);
  81. })(),
  82. (async () => {
  83. webhookUrl = await getWebhookUrl(localStorage.token);
  84. })(),
  85. (async () => {
  86. LDAP_SERVER = await getLdapServer(localStorage.token);
  87. })()
  88. ]);
  89. const ldapConfig = await getLdapConfig(localStorage.token);
  90. ENABLE_LDAP = ldapConfig.ENABLE_LDAP;
  91. });
  92. </script>
  93. <form
  94. class="flex flex-col h-full justify-between space-y-3 text-sm"
  95. on:submit|preventDefault={async () => {
  96. updateHandler();
  97. }}
  98. >
  99. <div class="mt-0.5 space-y-3 overflow-y-scroll scrollbar-hidden h-full">
  100. {#if adminConfig !== null}
  101. <div class="">
  102. <div class="mb-3.5">
  103. <div class=" mb-2.5 text-base font-medium">{$i18n.t('General')}</div>
  104. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  105. <div class="mb-2.5">
  106. <div class=" mb-1 text-xs font-medium flex space-x-2 items-center">
  107. <div>
  108. {$i18n.t('Version')}
  109. </div>
  110. </div>
  111. <div class="flex w-full justify-between items-center">
  112. <div class="flex flex-col text-xs text-gray-700 dark:text-gray-200">
  113. <div class="flex gap-1">
  114. <Tooltip content={WEBUI_BUILD_HASH}>
  115. v{WEBUI_VERSION}
  116. </Tooltip>
  117. <a
  118. href="https://github.com/open-webui/open-webui/releases/tag/v{version.latest}"
  119. target="_blank"
  120. >
  121. {updateAvailable === null
  122. ? $i18n.t('Checking for updates...')
  123. : updateAvailable
  124. ? `(v${version.latest} ${$i18n.t('available!')})`
  125. : $i18n.t('(latest)')}
  126. </a>
  127. </div>
  128. <button
  129. class=" underline flex items-center space-x-1 text-xs text-gray-500 dark:text-gray-500"
  130. type="button"
  131. on:click={() => {
  132. showChangelog.set(true);
  133. }}
  134. >
  135. <div>{$i18n.t("See what's new")}</div>
  136. </button>
  137. </div>
  138. <button
  139. class=" text-xs px-3 py-1.5 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
  140. type="button"
  141. on:click={() => {
  142. checkForVersionUpdates();
  143. }}
  144. >
  145. {$i18n.t('Check for updates')}
  146. </button>
  147. </div>
  148. </div>
  149. <div class="mb-2.5">
  150. <div class="flex w-full justify-between items-center">
  151. <div class="text-xs pr-2">
  152. <div class="">
  153. {$i18n.t('Help')}
  154. </div>
  155. <div class=" text-xs text-gray-500">
  156. {$i18n.t('Discover how to use Open WebUI and seek support from the community.')}
  157. </div>
  158. </div>
  159. <a
  160. class="flex-shrink-0 text-xs font-medium underline"
  161. href="https://docs.openwebui.com/"
  162. target="_blank"
  163. >
  164. {$i18n.t('Documentation')}
  165. </a>
  166. </div>
  167. <div class="mt-1">
  168. <div class="flex space-x-1">
  169. <a href="https://discord.gg/5rJgQTnV4s" target="_blank">
  170. <img
  171. alt="Discord"
  172. src="https://img.shields.io/badge/Discord-Open_WebUI-blue?logo=discord&logoColor=white"
  173. />
  174. </a>
  175. <a href="https://twitter.com/OpenWebUI" target="_blank">
  176. <img
  177. alt="X (formerly Twitter) Follow"
  178. src="https://img.shields.io/twitter/follow/OpenWebUI"
  179. />
  180. </a>
  181. <a href="https://github.com/open-webui/open-webui" target="_blank">
  182. <img
  183. alt="Github Repo"
  184. src="https://img.shields.io/github/stars/open-webui/open-webui?style=social&label=Star us on Github"
  185. />
  186. </a>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="mb-2.5">
  191. <div class="flex w-full justify-between items-center">
  192. <div class="text-xs pr-2">
  193. <div class="">
  194. {$i18n.t('License')}
  195. </div>
  196. <a
  197. class=" text-xs text-gray-500 hover:underline"
  198. href="https://docs.openwebui.com/enterprise"
  199. target="_blank"
  200. >
  201. {$i18n.t(
  202. 'Upgrade to a licensed plan for enhanced capabilities, including custom theming and branding, and dedicated support.'
  203. )}
  204. </a>
  205. </div>
  206. <!-- <button
  207. class="flex-shrink-0 text-xs px-3 py-1.5 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
  208. >
  209. {$i18n.t('Activate')}
  210. </button> -->
  211. </div>
  212. </div>
  213. </div>
  214. <div class="mb-3">
  215. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Authentication')}</div>
  216. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  217. <div class=" mb-2.5 flex w-full justify-between">
  218. <div class=" self-center text-xs font-medium">{$i18n.t('Default User Role')}</div>
  219. <div class="flex items-center relative">
  220. <select
  221. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 text-xs bg-transparent outline-hidden text-right"
  222. bind:value={adminConfig.DEFAULT_USER_ROLE}
  223. placeholder="Select a role"
  224. >
  225. <option value="pending">{$i18n.t('pending')}</option>
  226. <option value="user">{$i18n.t('user')}</option>
  227. <option value="admin">{$i18n.t('admin')}</option>
  228. </select>
  229. </div>
  230. </div>
  231. <div class=" mb-2.5 flex w-full justify-between pr-2">
  232. <div class=" self-center text-xs font-medium">{$i18n.t('Enable New Sign Ups')}</div>
  233. <Switch bind:state={adminConfig.ENABLE_SIGNUP} />
  234. </div>
  235. <div class="mb-2.5 flex w-full items-center justify-between pr-2">
  236. <div class=" self-center text-xs font-medium">
  237. {$i18n.t('Show Admin Details in Account Pending Overlay')}
  238. </div>
  239. <Switch bind:state={adminConfig.SHOW_ADMIN_DETAILS} />
  240. </div>
  241. <div class="mb-2.5 flex w-full justify-between pr-2">
  242. <div class=" self-center text-xs font-medium">{$i18n.t('Enable API Key')}</div>
  243. <Switch bind:state={adminConfig.ENABLE_API_KEY} />
  244. </div>
  245. {#if adminConfig?.ENABLE_API_KEY}
  246. <div class="mb-2.5 flex w-full justify-between pr-2">
  247. <div class=" self-center text-xs font-medium">
  248. {$i18n.t('API Key Endpoint Restrictions')}
  249. </div>
  250. <Switch bind:state={adminConfig.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS} />
  251. </div>
  252. {#if adminConfig?.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS}
  253. <div class=" flex w-full flex-col pr-2">
  254. <div class=" text-xs font-medium">
  255. {$i18n.t('Allowed Endpoints')}
  256. </div>
  257. <input
  258. class="w-full mt-1 rounded-lg text-sm dark:text-gray-300 bg-transparent outline-hidden"
  259. type="text"
  260. placeholder={`e.g.) /api/v1/messages, /api/v1/channels`}
  261. bind:value={adminConfig.API_KEY_ALLOWED_ENDPOINTS}
  262. />
  263. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  264. <!-- https://docs.openwebui.com/getting-started/advanced-topics/api-endpoints -->
  265. <a
  266. href="https://docs.openwebui.com/getting-started/api-endpoints"
  267. target="_blank"
  268. class=" text-gray-300 font-medium underline"
  269. >
  270. {$i18n.t('To learn more about available endpoints, visit our documentation.')}
  271. </a>
  272. </div>
  273. </div>
  274. {/if}
  275. {/if}
  276. <div class=" mb-2.5 w-full justify-between">
  277. <div class="flex w-full justify-between">
  278. <div class=" self-center text-xs font-medium">{$i18n.t('JWT Expiration')}</div>
  279. </div>
  280. <div class="flex mt-2 space-x-2">
  281. <input
  282. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
  283. type="text"
  284. placeholder={`e.g.) "30m","1h", "10d". `}
  285. bind:value={adminConfig.JWT_EXPIRES_IN}
  286. />
  287. </div>
  288. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  289. {$i18n.t('Valid time units:')}
  290. <span class=" text-gray-300 font-medium"
  291. >{$i18n.t("'s', 'm', 'h', 'd', 'w' or '-1' for no expiration.")}</span
  292. >
  293. </div>
  294. </div>
  295. <div class=" space-y-3">
  296. <div class="mt-2 space-y-2 pr-1.5">
  297. <div class="flex justify-between items-center text-sm">
  298. <div class=" font-medium">{$i18n.t('LDAP')}</div>
  299. <div class="mt-1">
  300. <Switch
  301. bind:state={ENABLE_LDAP}
  302. on:change={async () => {
  303. updateLdapConfig(localStorage.token, ENABLE_LDAP);
  304. }}
  305. />
  306. </div>
  307. </div>
  308. {#if ENABLE_LDAP}
  309. <div class="flex flex-col gap-1">
  310. <div class="flex w-full gap-2">
  311. <div class="w-full">
  312. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  313. {$i18n.t('Label')}
  314. </div>
  315. <input
  316. class="w-full bg-transparent outline-hidden py-0.5"
  317. required
  318. placeholder={$i18n.t('Enter server label')}
  319. bind:value={LDAP_SERVER.label}
  320. />
  321. </div>
  322. <div class="w-full"></div>
  323. </div>
  324. <div class="flex w-full gap-2">
  325. <div class="w-full">
  326. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  327. {$i18n.t('Host')}
  328. </div>
  329. <input
  330. class="w-full bg-transparent outline-hidden py-0.5"
  331. required
  332. placeholder={$i18n.t('Enter server host')}
  333. bind:value={LDAP_SERVER.host}
  334. />
  335. </div>
  336. <div class="w-full">
  337. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  338. {$i18n.t('Port')}
  339. </div>
  340. <Tooltip
  341. placement="top-start"
  342. content={$i18n.t('Default to 389 or 636 if TLS is enabled')}
  343. className="w-full"
  344. >
  345. <input
  346. class="w-full bg-transparent outline-hidden py-0.5"
  347. type="number"
  348. placeholder={$i18n.t('Enter server port')}
  349. bind:value={LDAP_SERVER.port}
  350. />
  351. </Tooltip>
  352. </div>
  353. </div>
  354. <div class="flex w-full gap-2">
  355. <div class="w-full">
  356. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  357. {$i18n.t('Application DN')}
  358. </div>
  359. <Tooltip
  360. content={$i18n.t('The Application Account DN you bind with for search')}
  361. placement="top-start"
  362. >
  363. <input
  364. class="w-full bg-transparent outline-hidden py-0.5"
  365. required
  366. placeholder={$i18n.t('Enter Application DN')}
  367. bind:value={LDAP_SERVER.app_dn}
  368. />
  369. </Tooltip>
  370. </div>
  371. <div class="w-full">
  372. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  373. {$i18n.t('Application DN Password')}
  374. </div>
  375. <SensitiveInput
  376. placeholder={$i18n.t('Enter Application DN Password')}
  377. bind:value={LDAP_SERVER.app_dn_password}
  378. />
  379. </div>
  380. </div>
  381. <div class="flex w-full gap-2">
  382. <div class="w-full">
  383. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  384. {$i18n.t('Attribute for Mail')}
  385. </div>
  386. <Tooltip
  387. content={$i18n.t(
  388. 'The LDAP attribute that maps to the mail that users use to sign in.'
  389. )}
  390. placement="top-start"
  391. >
  392. <input
  393. class="w-full bg-transparent outline-hidden py-0.5"
  394. required
  395. placeholder={$i18n.t('Example: mail')}
  396. bind:value={LDAP_SERVER.attribute_for_mail}
  397. />
  398. </Tooltip>
  399. </div>
  400. </div>
  401. <div class="flex w-full gap-2">
  402. <div class="w-full">
  403. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  404. {$i18n.t('Attribute for Username')}
  405. </div>
  406. <Tooltip
  407. content={$i18n.t(
  408. 'The LDAP attribute that maps to the username that users use to sign in.'
  409. )}
  410. placement="top-start"
  411. >
  412. <input
  413. class="w-full bg-transparent outline-hidden py-0.5"
  414. required
  415. placeholder={$i18n.t(
  416. 'Example: sAMAccountName or uid or userPrincipalName'
  417. )}
  418. bind:value={LDAP_SERVER.attribute_for_username}
  419. />
  420. </Tooltip>
  421. </div>
  422. </div>
  423. <div class="flex w-full gap-2">
  424. <div class="w-full">
  425. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  426. {$i18n.t('Search Base')}
  427. </div>
  428. <Tooltip
  429. content={$i18n.t('The base to search for users')}
  430. placement="top-start"
  431. >
  432. <input
  433. class="w-full bg-transparent outline-hidden py-0.5"
  434. required
  435. placeholder={$i18n.t('Example: ou=users,dc=foo,dc=example')}
  436. bind:value={LDAP_SERVER.search_base}
  437. />
  438. </Tooltip>
  439. </div>
  440. </div>
  441. <div class="flex w-full gap-2">
  442. <div class="w-full">
  443. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  444. {$i18n.t('Search Filters')}
  445. </div>
  446. <input
  447. class="w-full bg-transparent outline-hidden py-0.5"
  448. placeholder={$i18n.t('Example: (&(objectClass=inetOrgPerson)(uid=%s))')}
  449. bind:value={LDAP_SERVER.search_filters}
  450. />
  451. </div>
  452. </div>
  453. <div class="text-xs text-gray-400 dark:text-gray-500">
  454. <a
  455. class=" text-gray-300 font-medium underline"
  456. href="https://ldap.com/ldap-filters/"
  457. target="_blank"
  458. >
  459. {$i18n.t('Click here for filter guides.')}
  460. </a>
  461. </div>
  462. <div>
  463. <div class="flex justify-between items-center text-sm">
  464. <div class=" font-medium">{$i18n.t('TLS')}</div>
  465. <div class="mt-1">
  466. <Switch bind:state={LDAP_SERVER.use_tls} />
  467. </div>
  468. </div>
  469. {#if LDAP_SERVER.use_tls}
  470. <div class="flex w-full gap-2">
  471. <div class="w-full">
  472. <div class=" self-center text-xs font-medium min-w-fit mb-1 mt-1">
  473. {$i18n.t('Certificate Path')}
  474. </div>
  475. <input
  476. class="w-full bg-transparent outline-hidden py-0.5"
  477. required
  478. placeholder={$i18n.t('Enter certificate path')}
  479. bind:value={LDAP_SERVER.certificate_path}
  480. />
  481. </div>
  482. </div>
  483. <div class="flex w-full gap-2">
  484. <div class="w-full">
  485. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  486. {$i18n.t('Ciphers')}
  487. </div>
  488. <Tooltip content={$i18n.t('Default to ALL')} placement="top-start">
  489. <input
  490. class="w-full bg-transparent outline-hidden py-0.5"
  491. placeholder={$i18n.t('Example: ALL')}
  492. bind:value={LDAP_SERVER.ciphers}
  493. />
  494. </Tooltip>
  495. </div>
  496. <div class="w-full"></div>
  497. </div>
  498. {/if}
  499. </div>
  500. </div>
  501. {/if}
  502. </div>
  503. </div>
  504. </div>
  505. <div class="mb-3">
  506. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Features')}</div>
  507. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  508. <div class="mb-2.5 flex w-full items-center justify-between pr-2">
  509. <div class=" self-center text-xs font-medium">
  510. {$i18n.t('Enable Community Sharing')}
  511. </div>
  512. <Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
  513. </div>
  514. <div class="mb-2.5 flex w-full items-center justify-between pr-2">
  515. <div class=" self-center text-xs font-medium">{$i18n.t('Enable Message Rating')}</div>
  516. <Switch bind:state={adminConfig.ENABLE_MESSAGE_RATING} />
  517. </div>
  518. <div class="mb-2.5 flex w-full items-center justify-between pr-2">
  519. <div class=" self-center text-xs font-medium">
  520. {$i18n.t('Channels')} ({$i18n.t('Beta')})
  521. </div>
  522. <Switch bind:state={adminConfig.ENABLE_CHANNELS} />
  523. </div>
  524. <div class="mb-2.5 w-full justify-between">
  525. <div class="flex w-full justify-between">
  526. <div class=" self-center text-xs font-medium">{$i18n.t('WebUI URL')}</div>
  527. </div>
  528. <div class="flex mt-2 space-x-2">
  529. <input
  530. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
  531. type="text"
  532. placeholder={`e.g.) "http://localhost:3000"`}
  533. bind:value={adminConfig.WEBUI_URL}
  534. />
  535. </div>
  536. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  537. {$i18n.t(
  538. 'Enter the public URL of your WebUI. This URL will be used to generate links in the notifications.'
  539. )}
  540. </div>
  541. </div>
  542. <div class=" w-full justify-between">
  543. <div class="flex w-full justify-between">
  544. <div class=" self-center text-xs font-medium">{$i18n.t('Webhook URL')}</div>
  545. </div>
  546. <div class="flex mt-2 space-x-2">
  547. <input
  548. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
  549. type="text"
  550. placeholder={`https://example.com/webhook`}
  551. bind:value={webhookUrl}
  552. />
  553. </div>
  554. </div>
  555. </div>
  556. </div>
  557. {/if}
  558. </div>
  559. <div class="flex justify-end pt-3 text-sm font-medium">
  560. <button
  561. class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
  562. type="submit"
  563. >
  564. {$i18n.t('Save')}
  565. </button>
  566. </div>
  567. </form>