mirror of https://github.com/jetkvm/kvm.git
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.
This commit is contained in:
parent
4ab11a6af1
commit
54af0ab0fb
|
@ -85,6 +85,7 @@ type Config struct {
|
|||
HashedPassword string `json:"hashed_password"`
|
||||
LocalAuthToken string `json:"local_auth_token"`
|
||||
LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration
|
||||
LocalLoopbackOnly bool `json:"local_loopback_only"`
|
||||
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
|
||||
KeyboardMacros []KeyboardMacro `json:"keyboard_macros"`
|
||||
KeyboardLayout string `json:"keyboard_layout"`
|
||||
|
@ -95,7 +96,6 @@ type Config struct {
|
|||
DisplayDimAfterSec int `json:"display_dim_after_sec"`
|
||||
DisplayOffAfterSec int `json:"display_off_after_sec"`
|
||||
TLSMode string `json:"tls_mode"` // options: "self-signed", "user-defined", ""
|
||||
LocalWebServerLoopbackOnly bool `json:"local_web_server_loopback_only"`
|
||||
UsbConfig *usbgadget.Config `json:"usb_config"`
|
||||
UsbDevices *usbgadget.Devices `json:"usb_devices"`
|
||||
NetworkConfig *network.NetworkConfig `json:"network_config"`
|
||||
|
@ -116,7 +116,6 @@ var defaultConfig = &Config{
|
|||
DisplayDimAfterSec: 120, // 2 minutes
|
||||
DisplayOffAfterSec: 1800, // 30 minutes
|
||||
TLSMode: "",
|
||||
LocalWebServerLoopbackOnly: false, // Allow access from any network interface by default
|
||||
UsbConfig: &usbgadget.Config{
|
||||
VendorId: "0x1d6b", //The Linux Foundation
|
||||
ProductId: "0x0104", //Multifunction Composite Gadget
|
||||
|
|
14
jsonrpc.go
14
jsonrpc.go
|
@ -1006,18 +1006,18 @@ func setKeyboardMacros(params KeyboardMacrosParams) (interface{}, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func rpcGetLocalWebServerLoopbackOnly() (bool, error) {
|
||||
return config.LocalWebServerLoopbackOnly, nil
|
||||
func rpcGetLocalLoopbackOnly() (bool, error) {
|
||||
return config.LocalLoopbackOnly, nil
|
||||
}
|
||||
|
||||
func rpcSetLocalWebServerLoopbackOnly(enabled bool) error {
|
||||
func rpcSetLocalLoopbackOnly(enabled bool) error {
|
||||
// Check if the setting is actually changing
|
||||
if config.LocalWebServerLoopbackOnly == enabled {
|
||||
if config.LocalLoopbackOnly == enabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update the setting
|
||||
config.LocalWebServerLoopbackOnly = enabled
|
||||
config.LocalLoopbackOnly = enabled
|
||||
if err := SaveConfig(); err != nil {
|
||||
return fmt.Errorf("failed to save config: %w", err)
|
||||
}
|
||||
|
@ -1102,6 +1102,6 @@ var rpcHandlers = map[string]RPCHandler{
|
|||
"setKeyboardLayout": {Func: rpcSetKeyboardLayout, Params: []string{"layout"}},
|
||||
"getKeyboardMacros": {Func: getKeyboardMacros},
|
||||
"setKeyboardMacros": {Func: setKeyboardMacros, Params: []string{"params"}},
|
||||
"getLocalWebServerLoopbackOnly": {Func: rpcGetLocalWebServerLoopbackOnly},
|
||||
"setLocalWebServerLoopbackOnly": {Func: rpcSetLocalWebServerLoopbackOnly, Params: []string{"enabled"}},
|
||||
"getLocalLoopbackOnly": {Func: rpcGetLocalLoopbackOnly},
|
||||
"setLocalLoopbackOnly": {Func: rpcSetLocalLoopbackOnly, Params: []string{"enabled"}},
|
||||
}
|
||||
|
|
8
web.go
8
web.go
|
@ -54,7 +54,7 @@ type ChangePasswordRequest struct {
|
|||
type LocalDevice struct {
|
||||
AuthMode *string `json:"authMode"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
LocalWebServerLoopbackOnly bool `json:"localWebServerLoopbackOnly"`
|
||||
LoopbackOnly bool `json:"loopbackOnly"`
|
||||
}
|
||||
|
||||
type DeviceStatus struct {
|
||||
|
@ -536,11 +536,11 @@ func RunWebServer() {
|
|||
|
||||
// Determine the binding address based on the config
|
||||
bindAddress := ":80" // Default to all interfaces
|
||||
if config.LocalWebServerLoopbackOnly {
|
||||
if config.LocalLoopbackOnly {
|
||||
bindAddress = "localhost:80" // Loopback only (both IPv4 and IPv6)
|
||||
}
|
||||
|
||||
logger.Info().Str("bindAddress", bindAddress).Bool("loopbackOnly", config.LocalWebServerLoopbackOnly).Msg("Starting web server")
|
||||
logger.Info().Str("bindAddress", bindAddress).Bool("loopbackOnly", config.LocalLoopbackOnly).Msg("Starting web server")
|
||||
err := r.Run(bindAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -551,7 +551,7 @@ func handleDevice(c *gin.Context) {
|
|||
response := LocalDevice{
|
||||
AuthMode: &config.LocalAuthMode,
|
||||
DeviceID: GetDeviceID(),
|
||||
LocalWebServerLoopbackOnly: config.LocalWebServerLoopbackOnly,
|
||||
LoopbackOnly: config.LocalLoopbackOnly,
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response)
|
||||
|
|
Loading…
Reference in New Issue