General.svelte 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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 text-base font-medium">{$i18n.t('General')}</div>
  104. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  105. <div class="mb-2">
  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-100 hover:bg-gray-200 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
  140. on:click={() => {
  141. checkForVersionUpdates();
  142. }}
  143. >
  144. {$i18n.t('Check for updates')}
  145. </button>
  146. </div>
  147. </div>
  148. <div class="">
  149. <div class="flex w-full justify-between items-center">
  150. <div class="text-xs">
  151. <div class="">
  152. {$i18n.t('Help')}
  153. </div>
  154. <div class=" text-xs text-gray-500">
  155. Learn how to use Open WebUI and get help from the community.
  156. </div>
  157. </div>
  158. <a
  159. class=" text-xs font-medium underline"
  160. href="https://docs.openwebui.com/"
  161. target="_blank"
  162. >
  163. {$i18n.t('Documentation')}
  164. </a>
  165. </div>
  166. <div class="mt-1">
  167. <div class="flex space-x-1">
  168. <a href="https://discord.gg/5rJgQTnV4s" target="_blank">
  169. <img
  170. alt="Discord"
  171. src="https://img.shields.io/badge/Discord-Open_WebUI-blue?logo=discord&logoColor=white"
  172. />
  173. </a>
  174. <a href="https://twitter.com/OpenWebUI" target="_blank">
  175. <img
  176. alt="X (formerly Twitter) Follow"
  177. src="https://img.shields.io/twitter/follow/OpenWebUI"
  178. />
  179. </a>
  180. <a href="https://github.com/open-webui/open-webui" target="_blank">
  181. <img
  182. alt="Github Repo"
  183. src="https://img.shields.io/github/stars/open-webui/open-webui?style=social&label=Star us on Github"
  184. />
  185. </a>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="mb-3">
  191. <div class=" mb-2 text-base font-medium">{$i18n.t('Authentication')}</div>
  192. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  193. <div class=" mb-2 flex w-full justify-between">
  194. <div class=" self-center text-xs font-medium">{$i18n.t('Default User Role')}</div>
  195. <div class="flex items-center relative">
  196. <select
  197. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 text-xs bg-transparent outline-none text-right"
  198. bind:value={adminConfig.DEFAULT_USER_ROLE}
  199. placeholder="Select a role"
  200. >
  201. <option value="pending">{$i18n.t('pending')}</option>
  202. <option value="user">{$i18n.t('user')}</option>
  203. <option value="admin">{$i18n.t('admin')}</option>
  204. </select>
  205. </div>
  206. </div>
  207. <div class=" mb-2 flex w-full justify-between pr-2">
  208. <div class=" self-center text-xs font-medium">{$i18n.t('Enable New Sign Ups')}</div>
  209. <Switch bind:state={adminConfig.ENABLE_SIGNUP} />
  210. </div>
  211. <div class="mb-2 flex w-full items-center justify-between pr-2">
  212. <div class=" self-center text-xs font-medium">
  213. {$i18n.t('Show Admin Details in Account Pending Overlay')}
  214. </div>
  215. <Switch bind:state={adminConfig.SHOW_ADMIN_DETAILS} />
  216. </div>
  217. <div class="mb-2 flex w-full justify-between pr-2">
  218. <div class=" self-center text-xs font-medium">{$i18n.t('Enable API Key')}</div>
  219. <Switch bind:state={adminConfig.ENABLE_API_KEY} />
  220. </div>
  221. {#if adminConfig?.ENABLE_API_KEY}
  222. <div class="mb-2 flex w-full justify-between pr-2">
  223. <div class=" self-center text-xs font-medium">
  224. {$i18n.t('API Key Endpoint Restrictions')}
  225. </div>
  226. <Switch bind:state={adminConfig.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS} />
  227. </div>
  228. {#if adminConfig?.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS}
  229. <div class=" flex w-full flex-col pr-2">
  230. <div class=" text-xs font-medium">
  231. {$i18n.t('Allowed Endpoints')}
  232. </div>
  233. <input
  234. class="w-full mt-1 rounded-lg text-sm dark:text-gray-300 bg-transparent outline-none"
  235. type="text"
  236. placeholder={`e.g.) /api/v1/messages, /api/v1/channels`}
  237. bind:value={adminConfig.API_KEY_ALLOWED_ENDPOINTS}
  238. />
  239. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  240. <!-- https://docs.openwebui.com/getting-started/advanced-topics/api-endpoints -->
  241. <a
  242. href="https://docs.openwebui.com/getting-started/api-endpoints"
  243. target="_blank"
  244. class=" text-gray-300 font-medium underline"
  245. >
  246. {$i18n.t('To learn more about available endpoints, visit our documentation.')}
  247. </a>
  248. </div>
  249. </div>
  250. {/if}
  251. {/if}
  252. <div class=" mb-2 w-full justify-between">
  253. <div class="flex w-full justify-between">
  254. <div class=" self-center text-xs font-medium">{$i18n.t('JWT Expiration')}</div>
  255. </div>
  256. <div class="flex mt-2 space-x-2">
  257. <input
  258. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  259. type="text"
  260. placeholder={`e.g.) "30m","1h", "10d". `}
  261. bind:value={adminConfig.JWT_EXPIRES_IN}
  262. />
  263. </div>
  264. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  265. {$i18n.t('Valid time units:')}
  266. <span class=" text-gray-300 font-medium"
  267. >{$i18n.t("'s', 'm', 'h', 'd', 'w' or '-1' for no expiration.")}</span
  268. >
  269. </div>
  270. </div>
  271. <div class=" space-y-3">
  272. <div class="mt-2 space-y-2 pr-1.5">
  273. <div class="flex justify-between items-center text-sm">
  274. <div class=" font-medium">{$i18n.t('LDAP')}</div>
  275. <div class="mt-1">
  276. <Switch
  277. bind:state={ENABLE_LDAP}
  278. on:change={async () => {
  279. updateLdapConfig(localStorage.token, ENABLE_LDAP);
  280. }}
  281. />
  282. </div>
  283. </div>
  284. {#if ENABLE_LDAP}
  285. <div class="flex flex-col gap-1">
  286. <div class="flex w-full gap-2">
  287. <div class="w-full">
  288. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  289. {$i18n.t('Label')}
  290. </div>
  291. <input
  292. class="w-full bg-transparent outline-none py-0.5"
  293. required
  294. placeholder={$i18n.t('Enter server label')}
  295. bind:value={LDAP_SERVER.label}
  296. />
  297. </div>
  298. <div class="w-full"></div>
  299. </div>
  300. <div class="flex w-full gap-2">
  301. <div class="w-full">
  302. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  303. {$i18n.t('Host')}
  304. </div>
  305. <input
  306. class="w-full bg-transparent outline-none py-0.5"
  307. required
  308. placeholder={$i18n.t('Enter server host')}
  309. bind:value={LDAP_SERVER.host}
  310. />
  311. </div>
  312. <div class="w-full">
  313. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  314. {$i18n.t('Port')}
  315. </div>
  316. <Tooltip
  317. placement="top-start"
  318. content={$i18n.t('Default to 389 or 636 if TLS is enabled')}
  319. className="w-full"
  320. >
  321. <input
  322. class="w-full bg-transparent outline-none py-0.5"
  323. type="number"
  324. placeholder={$i18n.t('Enter server port')}
  325. bind:value={LDAP_SERVER.port}
  326. />
  327. </Tooltip>
  328. </div>
  329. </div>
  330. <div class="flex w-full gap-2">
  331. <div class="w-full">
  332. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  333. {$i18n.t('Application DN')}
  334. </div>
  335. <Tooltip
  336. content={$i18n.t('The Application Account DN you bind with for search')}
  337. placement="top-start"
  338. >
  339. <input
  340. class="w-full bg-transparent outline-none py-0.5"
  341. required
  342. placeholder={$i18n.t('Enter Application DN')}
  343. bind:value={LDAP_SERVER.app_dn}
  344. />
  345. </Tooltip>
  346. </div>
  347. <div class="w-full">
  348. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  349. {$i18n.t('Application DN Password')}
  350. </div>
  351. <SensitiveInput
  352. placeholder={$i18n.t('Enter Application DN Password')}
  353. bind:value={LDAP_SERVER.app_dn_password}
  354. />
  355. </div>
  356. </div>
  357. <div class="flex w-full gap-2">
  358. <div class="w-full">
  359. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  360. {$i18n.t('Attribute for Mail')}
  361. </div>
  362. <Tooltip
  363. content={$i18n.t(
  364. 'The LDAP attribute that maps to the mail that users use to sign in.'
  365. )}
  366. placement="top-start"
  367. >
  368. <input
  369. class="w-full bg-transparent outline-none py-0.5"
  370. required
  371. placeholder={$i18n.t('Example: mail')}
  372. bind:value={LDAP_SERVER.attribute_for_mail}
  373. />
  374. </Tooltip>
  375. </div>
  376. </div>
  377. <div class="flex w-full gap-2">
  378. <div class="w-full">
  379. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  380. {$i18n.t('Attribute for Username')}
  381. </div>
  382. <Tooltip
  383. content={$i18n.t(
  384. 'The LDAP attribute that maps to the username that users use to sign in.'
  385. )}
  386. placement="top-start"
  387. >
  388. <input
  389. class="w-full bg-transparent outline-none py-0.5"
  390. required
  391. placeholder={$i18n.t(
  392. 'Example: sAMAccountName or uid or userPrincipalName'
  393. )}
  394. bind:value={LDAP_SERVER.attribute_for_username}
  395. />
  396. </Tooltip>
  397. </div>
  398. </div>
  399. <div class="flex w-full gap-2">
  400. <div class="w-full">
  401. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  402. {$i18n.t('Search Base')}
  403. </div>
  404. <Tooltip
  405. content={$i18n.t('The base to search for users')}
  406. placement="top-start"
  407. >
  408. <input
  409. class="w-full bg-transparent outline-none py-0.5"
  410. required
  411. placeholder={$i18n.t('Example: ou=users,dc=foo,dc=example')}
  412. bind:value={LDAP_SERVER.search_base}
  413. />
  414. </Tooltip>
  415. </div>
  416. </div>
  417. <div class="flex w-full gap-2">
  418. <div class="w-full">
  419. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  420. {$i18n.t('Search Filters')}
  421. </div>
  422. <input
  423. class="w-full bg-transparent outline-none py-0.5"
  424. placeholder={$i18n.t('Example: (&(objectClass=inetOrgPerson)(uid=%s))')}
  425. bind:value={LDAP_SERVER.search_filters}
  426. />
  427. </div>
  428. </div>
  429. <div class="text-xs text-gray-400 dark:text-gray-500">
  430. <a
  431. class=" text-gray-300 font-medium underline"
  432. href="https://ldap.com/ldap-filters/"
  433. target="_blank"
  434. >
  435. {$i18n.t('Click here for filter guides.')}
  436. </a>
  437. </div>
  438. <div>
  439. <div class="flex justify-between items-center text-sm">
  440. <div class=" font-medium">{$i18n.t('TLS')}</div>
  441. <div class="mt-1">
  442. <Switch bind:state={LDAP_SERVER.use_tls} />
  443. </div>
  444. </div>
  445. {#if LDAP_SERVER.use_tls}
  446. <div class="flex w-full gap-2">
  447. <div class="w-full">
  448. <div class=" self-center text-xs font-medium min-w-fit mb-1 mt-1">
  449. {$i18n.t('Certificate Path')}
  450. </div>
  451. <input
  452. class="w-full bg-transparent outline-none py-0.5"
  453. required
  454. placeholder={$i18n.t('Enter certificate path')}
  455. bind:value={LDAP_SERVER.certificate_path}
  456. />
  457. </div>
  458. </div>
  459. <div class="flex w-full gap-2">
  460. <div class="w-full">
  461. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  462. {$i18n.t('Ciphers')}
  463. </div>
  464. <Tooltip content={$i18n.t('Default to ALL')} placement="top-start">
  465. <input
  466. class="w-full bg-transparent outline-none py-0.5"
  467. placeholder={$i18n.t('Example: ALL')}
  468. bind:value={LDAP_SERVER.ciphers}
  469. />
  470. </Tooltip>
  471. </div>
  472. <div class="w-full"></div>
  473. </div>
  474. {/if}
  475. </div>
  476. </div>
  477. {/if}
  478. </div>
  479. </div>
  480. </div>
  481. <div class="mb-3">
  482. <div class=" mb-2 text-base font-medium">{$i18n.t('Features')}</div>
  483. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  484. <div class="mb-2 flex w-full items-center justify-between pr-2">
  485. <div class=" self-center text-xs font-medium">
  486. {$i18n.t('Enable Community Sharing')}
  487. </div>
  488. <Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
  489. </div>
  490. <div class="mb-2 flex w-full items-center justify-between pr-2">
  491. <div class=" self-center text-xs font-medium">{$i18n.t('Enable Message Rating')}</div>
  492. <Switch bind:state={adminConfig.ENABLE_MESSAGE_RATING} />
  493. </div>
  494. <div class="mb-2 flex w-full items-center justify-between pr-2">
  495. <div class=" self-center text-xs font-medium">
  496. {$i18n.t('Channels')} ({$i18n.t('Beta')})
  497. </div>
  498. <Switch bind:state={adminConfig.ENABLE_CHANNELS} />
  499. </div>
  500. <div class="mb-2 w-full justify-between">
  501. <div class="flex w-full justify-between">
  502. <div class=" self-center text-xs font-medium">{$i18n.t('WebUI URL')}</div>
  503. </div>
  504. <div class="flex mt-2 space-x-2">
  505. <input
  506. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  507. type="text"
  508. placeholder={`e.g.) "http://localhost:3000"`}
  509. bind:value={adminConfig.WEBUI_URL}
  510. />
  511. </div>
  512. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  513. {$i18n.t(
  514. 'Enter the public URL of your WebUI. This URL will be used to generate links in the notifications.'
  515. )}
  516. </div>
  517. </div>
  518. <div class=" w-full justify-between">
  519. <div class="flex w-full justify-between">
  520. <div class=" self-center text-xs font-medium">{$i18n.t('Webhook URL')}</div>
  521. </div>
  522. <div class="flex mt-2 space-x-2">
  523. <input
  524. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  525. type="text"
  526. placeholder={`https://example.com/webhook`}
  527. bind:value={webhookUrl}
  528. />
  529. </div>
  530. </div>
  531. </div>
  532. </div>
  533. {/if}
  534. </div>
  535. <div class="flex justify-end pt-3 text-sm font-medium">
  536. <button
  537. 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"
  538. type="submit"
  539. >
  540. {$i18n.t('Save')}
  541. </button>
  542. </div>
  543. </form>