fix: admin/options: error after enabling https if you are browsing not with localhost #802
Massimo Melina committed
Nov 20, 2024 at 21:38 UTC
f2aaf0a4cc2b9496e811a819b7dd500a4d92aea4
2 files changed
+13
-8
admin/src/LogsPage.ts
+1
-1
@@ -17,7 +17,7 @@ import _ from 'lodash'
17
import { AutoDelete, ClearAll, Delete, Download, Settings, SmartToy } from '@mui/icons-material'
18
import { ConfigForm } from './ConfigForm'
19
import { BoolField, SelectField } from '@hfs/mui-grid-form'
20
-import { alertDialog, toast, useDialogBarColors } from './dialog'
20
+import { toast, useDialogBarColors } from './dialog'
21
import { useBlockIp } from './useBlockIp'
22
import { ALL as COUNTRIES } from './countries'
23
admin/src/OptionsPage.ts
+12
-7
@@ -7,8 +7,10 @@ import { state, useSnapState } from './state'
7
import { Link as RouterLink } from 'react-router-dom'
8
import { CardMembership, EditNote, Refresh, Warning } from '@mui/icons-material'
9
import { adminApis } from '../../src/adminApis'
10
-import { Dict, MAX_TILE_SIZE, REPO_URL, wait, with_, try_, ipForUrl, SORT_BY_OPTIONS, THEME_OPTIONS,
11
- CFG, md, IMAGE_FILEMASK } from './misc'
10
+import {
11
+ MAX_TILE_SIZE, REPO_URL, SORT_BY_OPTIONS, THEME_OPTIONS, PORT_DISABLED, CFG, IMAGE_FILEMASK,
12
+ Dict, md, wait, with_, try_, ipForUrl,
13
+} from './misc'
14
import { iconTooltip, InLink, LinkBtn, propsForModifiedValues, wikiLink, useBreakpoint, NetmaskField, WildcardsSupported } from './mui'
15
import { Form, BoolField, NumberField, SelectField, FieldProps, Field, StringField } from '@hfs/mui-grid-form';
16
import { ArrayField } from './ArrayField'
@@ -273,12 +275,15 @@ export default function OptionsPage() {
275
if (onHttps && certChange && !await confirmDialog("You may disrupt https service, kicking you out"))
276
return
277
await apiCall('set_config', { values: changes })
276
- if (newPort !== undefined) {
278
+ const ip = ipForUrl(loc.hostname)
279
+ const path = loc.pathname + loc.hash
280
+ const redirect = newPort <= 0 ? `${onHttps ? 'http:' : 'https:'}//${ip}:${otherPort}${path}` // jump protocol also in case of random port, because people must know their port while using GUI
281
+ : newPort ? `${loc.protocol}//${ip}:${newPort || values[keys[0]]}${path}`
282
+ : await with_(`https://${ip}:${loc.port}${path}`, httpsUrl => // could we be kicked out because of force_https?
283
+ !onHttps && (changes.force_https ?? data.force_https) && fetch(httpsUrl).then(() => httpsUrl, () => 0)) // only happens if https is working
284
+ if (redirect) {
285
await alertDialog("You are being redirected but in some cases this may fail. Hold on tight!", 'warning')
278
- const x = ipForUrl(loc.hostname)
279
- // we have to jump protocol also in case of random port, because we want people to know their port while using GUI
280
- return window.location.href = newPort <= 0 ? `${onHttps ? 'http:' : 'https:'}//${x}:${otherPort}${loc.pathname}`
281
- : `${loc.protocol}//${x}:${newPort || values[keys[0]]}${loc.pathname}`
286
+ return window.location.href = redirect
287
}
288
const portChange = 'port' in changes || 'https_port' in changes
289
setTimeout(reloadStatus, portChange || certChange ? 1000 : 0) // give some time to apply news