mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
feat: add local web server loopback mode configuration (#511)
* feat: add local web server loopback mode configuration - Introduced a new configuration option `LocalWebServerLoopbackOnly` to restrict the web server to listen only on the loopback interface. - Added RPC methods `rpcGetLocalWebServerLoopbackOnly` and `rpcSetLocalWebServerLoopbackOnly` for retrieving and updating this setting. - Updated the web server startup logic to bind to the appropriate address based on the new configuration. - Modified the `LocalDevice` struct to include the loopback setting in the response. * remove extra logs * chore: add VSCode extensions for improved development environment * refactor: rename LocalWebServerLoopbackOnly to LocalLoopbackOnly - Updated the configuration struct and related RPC methods to use the new name `LocalLoopbackOnly` for clarity. - Adjusted the web server binding logic and device response structure to reflect this change. * feat: add loopback-only mode functionality to UI - Implemented a new setting for enabling loopback-only mode, restricting web interface access to localhost. - Added a confirmation dialog to warn users before enabling this feature. - Updated the ConfirmDialog component to accept React nodes for the description prop. - Refactored imports and adjusted component structure for clarity. * refactor: optimize device settings handlers for better performance - Refactored the `handleDevChannelChange` and `handleLoopbackOnlyModeChange` functions to use `useCallback` for improved performance and to prevent unnecessary re-renders. - Consolidated the logic for applying loopback-only mode into a separate `applyLoopbackOnlyMode` function, enhancing code clarity and maintainability. - Updated the confirmation flow for enabling loopback-only mode to ensure user warnings are displayed appropriately.
This commit is contained in:
20
web.go
20
web.go
@@ -52,8 +52,9 @@ type ChangePasswordRequest struct {
|
||||
}
|
||||
|
||||
type LocalDevice struct {
|
||||
AuthMode *string `json:"authMode"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
AuthMode *string `json:"authMode"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
LoopbackOnly bool `json:"loopbackOnly"`
|
||||
}
|
||||
|
||||
type DeviceStatus struct {
|
||||
@@ -532,7 +533,15 @@ func basicAuthProtectedMiddleware(requireDeveloperMode bool) gin.HandlerFunc {
|
||||
|
||||
func RunWebServer() {
|
||||
r := setupRouter()
|
||||
err := r.Run(":80")
|
||||
|
||||
// Determine the binding address based on the config
|
||||
bindAddress := ":80" // Default to all interfaces
|
||||
if config.LocalLoopbackOnly {
|
||||
bindAddress = "localhost:80" // Loopback only (both IPv4 and IPv6)
|
||||
}
|
||||
|
||||
logger.Info().Str("bindAddress", bindAddress).Bool("loopbackOnly", config.LocalLoopbackOnly).Msg("Starting web server")
|
||||
err := r.Run(bindAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -540,8 +549,9 @@ func RunWebServer() {
|
||||
|
||||
func handleDevice(c *gin.Context) {
|
||||
response := LocalDevice{
|
||||
AuthMode: &config.LocalAuthMode,
|
||||
DeviceID: GetDeviceID(),
|
||||
AuthMode: &config.LocalAuthMode,
|
||||
DeviceID: GetDeviceID(),
|
||||
LoopbackOnly: config.LocalLoopbackOnly,
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response)
|
||||
|
||||
Reference in New Issue
Block a user