General.svelte 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <script lang="ts">
  2. import { getBackendConfig, 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 { config } from '$lib/stores';
  15. import { onMount, getContext } from 'svelte';
  16. import { toast } from 'svelte-sonner';
  17. const i18n = getContext('i18n');
  18. export let saveHandler: Function;
  19. let adminConfig = null;
  20. let webhookUrl = '';
  21. // LDAP
  22. let ENABLE_LDAP = false;
  23. let LDAP_SERVER = {
  24. label: '',
  25. host: '',
  26. port: '',
  27. attribute_for_mail: 'mail',
  28. attribute_for_username: 'uid',
  29. app_dn: '',
  30. app_dn_password: '',
  31. search_base: '',
  32. search_filters: '',
  33. use_tls: false,
  34. certificate_path: '',
  35. ciphers: ''
  36. };
  37. const updateLdapServerHandler = async () => {
  38. if (!ENABLE_LDAP) return;
  39. const res = await updateLdapServer(localStorage.token, LDAP_SERVER).catch((error) => {
  40. toast.error(`${error}`);
  41. return null;
  42. });
  43. if (res) {
  44. toast.success($i18n.t('LDAP server updated'));
  45. }
  46. };
  47. const updateHandler = async () => {
  48. webhookUrl = await updateWebhookUrl(localStorage.token, webhookUrl);
  49. const res = await updateAdminConfig(localStorage.token, adminConfig);
  50. await updateLdapServerHandler();
  51. if (res) {
  52. saveHandler();
  53. } else {
  54. toast.error(i18n.t('Failed to update settings'));
  55. }
  56. };
  57. onMount(async () => {
  58. await Promise.all([
  59. (async () => {
  60. adminConfig = await getAdminConfig(localStorage.token);
  61. })(),
  62. (async () => {
  63. webhookUrl = await getWebhookUrl(localStorage.token);
  64. })(),
  65. (async () => {
  66. LDAP_SERVER = await getLdapServer(localStorage.token);
  67. })()
  68. ]);
  69. const ldapConfig = await getLdapConfig(localStorage.token);
  70. ENABLE_LDAP = ldapConfig.ENABLE_LDAP;
  71. });
  72. </script>
  73. <form
  74. class="flex flex-col h-full justify-between space-y-3 text-sm"
  75. on:submit|preventDefault={async () => {
  76. updateHandler();
  77. }}
  78. >
  79. <div class=" space-y-3 overflow-y-scroll scrollbar-hidden h-full">
  80. {#if adminConfig !== null}
  81. <div>
  82. <div class=" mb-3 text-sm font-medium">{$i18n.t('General Settings')}</div>
  83. <div class=" flex w-full justify-between pr-2">
  84. <div class=" self-center text-xs font-medium">{$i18n.t('Enable New Sign Ups')}</div>
  85. <Switch bind:state={adminConfig.ENABLE_SIGNUP} />
  86. </div>
  87. <div class=" my-3 flex w-full justify-between">
  88. <div class=" self-center text-xs font-medium">{$i18n.t('Default User Role')}</div>
  89. <div class="flex items-center relative">
  90. <select
  91. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 text-xs bg-transparent outline-none text-right"
  92. bind:value={adminConfig.DEFAULT_USER_ROLE}
  93. placeholder="Select a role"
  94. >
  95. <option value="pending">{$i18n.t('pending')}</option>
  96. <option value="user">{$i18n.t('user')}</option>
  97. <option value="admin">{$i18n.t('admin')}</option>
  98. </select>
  99. </div>
  100. </div>
  101. <div class=" flex w-full justify-between pr-2 my-3">
  102. <div class=" self-center text-xs font-medium">{$i18n.t('Enable API Key')}</div>
  103. <Switch bind:state={adminConfig.ENABLE_API_KEY} />
  104. </div>
  105. {#if adminConfig?.ENABLE_API_KEY}
  106. <div class=" flex w-full justify-between pr-2 my-3">
  107. <div class=" self-center text-xs font-medium">
  108. {$i18n.t('API Key Endpoint Restrictions')}
  109. </div>
  110. <Switch bind:state={adminConfig.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS} />
  111. </div>
  112. {#if adminConfig?.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS}
  113. <div class=" flex w-full flex-col pr-2">
  114. <div class=" text-xs font-medium">
  115. {$i18n.t('Allowed Endpoints')}
  116. </div>
  117. <input
  118. class="w-full mt-1 rounded-lg text-sm dark:text-gray-300 bg-transparent outline-none"
  119. type="text"
  120. placeholder={`e.g.) /api/v1/messages, /api/v1/channels`}
  121. bind:value={adminConfig.API_KEY_ALLOWED_ENDPOINTS}
  122. />
  123. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  124. <!-- https://docs.openwebui.com/getting-started/advanced-topics/api-endpoints -->
  125. <a
  126. href="https://docs.openwebui.com/getting-started/advanced-topics/api-endpoints"
  127. target="_blank"
  128. class=" text-gray-300 font-medium underline"
  129. >
  130. {$i18n.t('To learn more about available endpoints, visit our documentation.')}
  131. </a>
  132. </div>
  133. </div>
  134. {/if}
  135. {/if}
  136. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  137. <div class="my-3 flex w-full items-center justify-between pr-2">
  138. <div class=" self-center text-xs font-medium">
  139. {$i18n.t('Show Admin Details in Account Pending Overlay')}
  140. </div>
  141. <Switch bind:state={adminConfig.SHOW_ADMIN_DETAILS} />
  142. </div>
  143. <div class="my-3 flex w-full items-center justify-between pr-2">
  144. <div class=" self-center text-xs font-medium">{$i18n.t('Enable Community Sharing')}</div>
  145. <Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
  146. </div>
  147. <div class="my-3 flex w-full items-center justify-between pr-2">
  148. <div class=" self-center text-xs font-medium">{$i18n.t('Enable Message Rating')}</div>
  149. <Switch bind:state={adminConfig.ENABLE_MESSAGE_RATING} />
  150. </div>
  151. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  152. <div class=" w-full justify-between">
  153. <div class="flex w-full justify-between">
  154. <div class=" self-center text-xs font-medium">{$i18n.t('WebUI URL')}</div>
  155. </div>
  156. <div class="flex mt-2 space-x-2">
  157. <input
  158. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  159. type="text"
  160. placeholder={`e.g.) "http://localhost:3000"`}
  161. bind:value={adminConfig.WEBUI_URL}
  162. />
  163. </div>
  164. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  165. {$i18n.t(
  166. 'Enter the public URL of your WebUI. This URL will be used to generate links in the notifications.'
  167. )}
  168. </div>
  169. </div>
  170. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  171. <div class=" w-full justify-between">
  172. <div class="flex w-full justify-between">
  173. <div class=" self-center text-xs font-medium">{$i18n.t('JWT Expiration')}</div>
  174. </div>
  175. <div class="flex mt-2 space-x-2">
  176. <input
  177. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  178. type="text"
  179. placeholder={`e.g.) "30m","1h", "10d". `}
  180. bind:value={adminConfig.JWT_EXPIRES_IN}
  181. />
  182. </div>
  183. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  184. {$i18n.t('Valid time units:')}
  185. <span class=" text-gray-300 font-medium"
  186. >{$i18n.t("'s', 'm', 'h', 'd', 'w' or '-1' for no expiration.")}</span
  187. >
  188. </div>
  189. </div>
  190. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  191. <div class=" w-full justify-between">
  192. <div class="flex w-full justify-between">
  193. <div class=" self-center text-xs font-medium">{$i18n.t('Webhook URL')}</div>
  194. </div>
  195. <div class="flex mt-2 space-x-2">
  196. <input
  197. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  198. type="text"
  199. placeholder={`https://example.com/webhook`}
  200. bind:value={webhookUrl}
  201. />
  202. </div>
  203. </div>
  204. <hr class=" border-gray-50 dark:border-gray-850 my-2" />
  205. <div class="pt-1 flex w-full justify-between pr-2">
  206. <div class=" self-center text-sm font-medium">
  207. {$i18n.t('Channels')} ({$i18n.t('Beta')})
  208. </div>
  209. <Switch bind:state={adminConfig.ENABLE_CHANNELS} />
  210. </div>
  211. </div>
  212. {/if}
  213. <hr class=" border-gray-50 dark:border-gray-850" />
  214. <div class=" space-y-3">
  215. <div class="mt-2 space-y-2 pr-1.5">
  216. <div class="flex justify-between items-center text-sm">
  217. <div class=" font-medium">{$i18n.t('LDAP')}</div>
  218. <div class="mt-1">
  219. <Switch
  220. bind:state={ENABLE_LDAP}
  221. on:change={async () => {
  222. updateLdapConfig(localStorage.token, ENABLE_LDAP);
  223. }}
  224. />
  225. </div>
  226. </div>
  227. {#if ENABLE_LDAP}
  228. <div class="flex flex-col gap-1">
  229. <div class="flex w-full gap-2">
  230. <div class="w-full">
  231. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  232. {$i18n.t('Label')}
  233. </div>
  234. <input
  235. class="w-full bg-transparent outline-none py-0.5"
  236. required
  237. placeholder={$i18n.t('Enter server label')}
  238. bind:value={LDAP_SERVER.label}
  239. />
  240. </div>
  241. <div class="w-full"></div>
  242. </div>
  243. <div class="flex w-full gap-2">
  244. <div class="w-full">
  245. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  246. {$i18n.t('Host')}
  247. </div>
  248. <input
  249. class="w-full bg-transparent outline-none py-0.5"
  250. required
  251. placeholder={$i18n.t('Enter server host')}
  252. bind:value={LDAP_SERVER.host}
  253. />
  254. </div>
  255. <div class="w-full">
  256. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  257. {$i18n.t('Port')}
  258. </div>
  259. <Tooltip
  260. placement="top-start"
  261. content={$i18n.t('Default to 389 or 636 if TLS is enabled')}
  262. className="w-full"
  263. >
  264. <input
  265. class="w-full bg-transparent outline-none py-0.5"
  266. type="number"
  267. placeholder={$i18n.t('Enter server port')}
  268. bind:value={LDAP_SERVER.port}
  269. />
  270. </Tooltip>
  271. </div>
  272. </div>
  273. <div class="flex w-full gap-2">
  274. <div class="w-full">
  275. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  276. {$i18n.t('Application DN')}
  277. </div>
  278. <Tooltip
  279. content={$i18n.t('The Application Account DN you bind with for search')}
  280. placement="top-start"
  281. >
  282. <input
  283. class="w-full bg-transparent outline-none py-0.5"
  284. required
  285. placeholder={$i18n.t('Enter Application DN')}
  286. bind:value={LDAP_SERVER.app_dn}
  287. />
  288. </Tooltip>
  289. </div>
  290. <div class="w-full">
  291. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  292. {$i18n.t('Application DN Password')}
  293. </div>
  294. <SensitiveInput
  295. placeholder={$i18n.t('Enter Application DN Password')}
  296. bind:value={LDAP_SERVER.app_dn_password}
  297. />
  298. </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('Attribute for Mail')}
  304. </div>
  305. <Tooltip
  306. content={$i18n.t(
  307. 'The LDAP attribute that maps to the mail that users use to sign in.'
  308. )}
  309. placement="top-start"
  310. >
  311. <input
  312. class="w-full bg-transparent outline-none py-0.5"
  313. required
  314. placeholder={$i18n.t('Example: mail')}
  315. bind:value={LDAP_SERVER.attribute_for_mail}
  316. />
  317. </Tooltip>
  318. </div>
  319. </div>
  320. <div class="flex w-full gap-2">
  321. <div class="w-full">
  322. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  323. {$i18n.t('Attribute for Username')}
  324. </div>
  325. <Tooltip
  326. content={$i18n.t(
  327. 'The LDAP attribute that maps to the username that users use to sign in.'
  328. )}
  329. placement="top-start"
  330. >
  331. <input
  332. class="w-full bg-transparent outline-none py-0.5"
  333. required
  334. placeholder={$i18n.t('Example: sAMAccountName or uid or userPrincipalName')}
  335. bind:value={LDAP_SERVER.attribute_for_username}
  336. />
  337. </Tooltip>
  338. </div>
  339. </div>
  340. <div class="flex w-full gap-2">
  341. <div class="w-full">
  342. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  343. {$i18n.t('Search Base')}
  344. </div>
  345. <Tooltip content={$i18n.t('The base to search for users')} placement="top-start">
  346. <input
  347. class="w-full bg-transparent outline-none py-0.5"
  348. required
  349. placeholder={$i18n.t('Example: ou=users,dc=foo,dc=example')}
  350. bind:value={LDAP_SERVER.search_base}
  351. />
  352. </Tooltip>
  353. </div>
  354. </div>
  355. <div class="flex w-full gap-2">
  356. <div class="w-full">
  357. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  358. {$i18n.t('Search Filters')}
  359. </div>
  360. <input
  361. class="w-full bg-transparent outline-none py-0.5"
  362. placeholder={$i18n.t('Example: (&(objectClass=inetOrgPerson)(uid=%s))')}
  363. bind:value={LDAP_SERVER.search_filters}
  364. />
  365. </div>
  366. </div>
  367. <div class="text-xs text-gray-400 dark:text-gray-500">
  368. <a
  369. class=" text-gray-300 font-medium underline"
  370. href="https://ldap.com/ldap-filters/"
  371. target="_blank"
  372. >
  373. {$i18n.t('Click here for filter guides.')}
  374. </a>
  375. </div>
  376. <div>
  377. <div class="flex justify-between items-center text-sm">
  378. <div class=" font-medium">{$i18n.t('TLS')}</div>
  379. <div class="mt-1">
  380. <Switch bind:state={LDAP_SERVER.use_tls} />
  381. </div>
  382. </div>
  383. {#if LDAP_SERVER.use_tls}
  384. <div class="flex w-full gap-2">
  385. <div class="w-full">
  386. <div class=" self-center text-xs font-medium min-w-fit mb-1 mt-1">
  387. {$i18n.t('Certificate Path')}
  388. </div>
  389. <input
  390. class="w-full bg-transparent outline-none py-0.5"
  391. required
  392. placeholder={$i18n.t('Enter certificate path')}
  393. bind:value={LDAP_SERVER.certificate_path}
  394. />
  395. </div>
  396. </div>
  397. <div class="flex w-full gap-2">
  398. <div class="w-full">
  399. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  400. {$i18n.t('Ciphers')}
  401. </div>
  402. <Tooltip content={$i18n.t('Default to ALL')} placement="top-start">
  403. <input
  404. class="w-full bg-transparent outline-none py-0.5"
  405. placeholder={$i18n.t('Example: ALL')}
  406. bind:value={LDAP_SERVER.ciphers}
  407. />
  408. </Tooltip>
  409. </div>
  410. <div class="w-full"></div>
  411. </div>
  412. {/if}
  413. </div>
  414. </div>
  415. {/if}
  416. </div>
  417. </div>
  418. </div>
  419. <div class="flex justify-end pt-3 text-sm font-medium">
  420. <button
  421. 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"
  422. type="submit"
  423. >
  424. {$i18n.t('Save')}
  425. </button>
  426. </div>
  427. </form>