mirror of https://github.com/jetkvm/kvm.git
fix: reset config
This commit is contained in:
parent
459dc5c9fa
commit
775b0f1049
72
config.go
72
config.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/jetkvm/kvm/internal/confparser"
|
||||||
"github.com/jetkvm/kvm/internal/logging"
|
"github.com/jetkvm/kvm/internal/logging"
|
||||||
"github.com/jetkvm/kvm/internal/network/types"
|
"github.com/jetkvm/kvm/internal/network/types"
|
||||||
"github.com/jetkvm/kvm/internal/usbgadget"
|
"github.com/jetkvm/kvm/internal/usbgadget"
|
||||||
|
|
@ -128,41 +129,55 @@ func (c *Config) SetDisplayRotation(rotation string) error {
|
||||||
|
|
||||||
const configPath = "/userdata/kvm_config.json"
|
const configPath = "/userdata/kvm_config.json"
|
||||||
|
|
||||||
var defaultConfig = &Config{
|
// it's a temporary solution to avoid sharing the same pointer
|
||||||
CloudURL: "https://api.jetkvm.com",
|
// we should migrate to a proper config solution in the future
|
||||||
CloudAppURL: "https://app.jetkvm.com",
|
var (
|
||||||
AutoUpdateEnabled: true, // Set a default value
|
defaultJigglerConfig = JigglerConfig{
|
||||||
ActiveExtension: "",
|
|
||||||
KeyboardMacros: []KeyboardMacro{},
|
|
||||||
DisplayRotation: "270",
|
|
||||||
KeyboardLayout: "en-US",
|
|
||||||
DisplayMaxBrightness: 64,
|
|
||||||
DisplayDimAfterSec: 120, // 2 minutes
|
|
||||||
DisplayOffAfterSec: 1800, // 30 minutes
|
|
||||||
JigglerEnabled: false,
|
|
||||||
// This is the "Standard" jiggler option in the UI
|
|
||||||
JigglerConfig: &JigglerConfig{
|
|
||||||
InactivityLimitSeconds: 60,
|
InactivityLimitSeconds: 60,
|
||||||
JitterPercentage: 25,
|
JitterPercentage: 25,
|
||||||
ScheduleCronTab: "0 * * * * *",
|
ScheduleCronTab: "0 * * * * *",
|
||||||
Timezone: "UTC",
|
Timezone: "UTC",
|
||||||
},
|
}
|
||||||
TLSMode: "",
|
defaultUsbConfig = usbgadget.Config{
|
||||||
UsbConfig: &usbgadget.Config{
|
|
||||||
VendorId: "0x1d6b", //The Linux Foundation
|
VendorId: "0x1d6b", //The Linux Foundation
|
||||||
ProductId: "0x0104", //Multifunction Composite Gadget
|
ProductId: "0x0104", //Multifunction Composite Gadget
|
||||||
SerialNumber: "",
|
SerialNumber: "",
|
||||||
Manufacturer: "JetKVM",
|
Manufacturer: "JetKVM",
|
||||||
Product: "USB Emulation Device",
|
Product: "USB Emulation Device",
|
||||||
},
|
}
|
||||||
UsbDevices: &usbgadget.Devices{
|
defaultUsbDevices = usbgadget.Devices{
|
||||||
AbsoluteMouse: true,
|
AbsoluteMouse: true,
|
||||||
RelativeMouse: true,
|
RelativeMouse: true,
|
||||||
Keyboard: true,
|
Keyboard: true,
|
||||||
MassStorage: true,
|
MassStorage: true,
|
||||||
},
|
}
|
||||||
NetworkConfig: &types.NetworkConfig{},
|
)
|
||||||
DefaultLogLevel: "INFO",
|
|
||||||
|
func getDefaultConfig() Config {
|
||||||
|
return Config{
|
||||||
|
CloudURL: "https://api.jetkvm.com",
|
||||||
|
CloudAppURL: "https://app.jetkvm.com",
|
||||||
|
AutoUpdateEnabled: true, // Set a default value
|
||||||
|
ActiveExtension: "",
|
||||||
|
KeyboardMacros: []KeyboardMacro{},
|
||||||
|
DisplayRotation: "270",
|
||||||
|
KeyboardLayout: "en-US",
|
||||||
|
DisplayMaxBrightness: 64,
|
||||||
|
DisplayDimAfterSec: 120, // 2 minutes
|
||||||
|
DisplayOffAfterSec: 1800, // 30 minutes
|
||||||
|
JigglerEnabled: false,
|
||||||
|
// This is the "Standard" jiggler option in the UI
|
||||||
|
JigglerConfig: func() *JigglerConfig { c := defaultJigglerConfig; return &c }(),
|
||||||
|
TLSMode: "",
|
||||||
|
UsbConfig: func() *usbgadget.Config { c := defaultUsbConfig; return &c }(),
|
||||||
|
UsbDevices: func() *usbgadget.Devices { c := defaultUsbDevices; return &c }(),
|
||||||
|
NetworkConfig: func() *types.NetworkConfig {
|
||||||
|
c := &types.NetworkConfig{}
|
||||||
|
_ = confparser.SetDefaultsAndValidate(c)
|
||||||
|
return c
|
||||||
|
}(),
|
||||||
|
DefaultLogLevel: "INFO",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -195,7 +210,8 @@ func LoadConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the default config
|
// load the default config
|
||||||
config = defaultConfig
|
defaultConfig := getDefaultConfig()
|
||||||
|
config = &defaultConfig
|
||||||
|
|
||||||
file, err := os.Open(configPath)
|
file, err := os.Open(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -207,7 +223,7 @@ func LoadConfig() {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// load and merge the default config with the user config
|
// load and merge the default config with the user config
|
||||||
loadedConfig := *defaultConfig
|
loadedConfig := defaultConfig
|
||||||
if err := json.NewDecoder(file).Decode(&loadedConfig); err != nil {
|
if err := json.NewDecoder(file).Decode(&loadedConfig); err != nil {
|
||||||
logger.Warn().Err(err).Msg("config file JSON parsing failed")
|
logger.Warn().Err(err).Msg("config file JSON parsing failed")
|
||||||
configSuccess.Set(0.0)
|
configSuccess.Set(0.0)
|
||||||
|
|
@ -216,19 +232,19 @@ func LoadConfig() {
|
||||||
|
|
||||||
// merge the user config with the default config
|
// merge the user config with the default config
|
||||||
if loadedConfig.UsbConfig == nil {
|
if loadedConfig.UsbConfig == nil {
|
||||||
loadedConfig.UsbConfig = defaultConfig.UsbConfig
|
loadedConfig.UsbConfig = getDefaultConfig().UsbConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
if loadedConfig.UsbDevices == nil {
|
if loadedConfig.UsbDevices == nil {
|
||||||
loadedConfig.UsbDevices = defaultConfig.UsbDevices
|
loadedConfig.UsbDevices = getDefaultConfig().UsbDevices
|
||||||
}
|
}
|
||||||
|
|
||||||
if loadedConfig.NetworkConfig == nil {
|
if loadedConfig.NetworkConfig == nil {
|
||||||
loadedConfig.NetworkConfig = defaultConfig.NetworkConfig
|
loadedConfig.NetworkConfig = getDefaultConfig().NetworkConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
if loadedConfig.JigglerConfig == nil {
|
if loadedConfig.JigglerConfig == nil {
|
||||||
loadedConfig.JigglerConfig = defaultConfig.JigglerConfig
|
loadedConfig.JigglerConfig = getDefaultConfig().JigglerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixup old keyboard layout value
|
// fixup old keyboard layout value
|
||||||
|
|
|
||||||
|
|
@ -720,7 +720,8 @@ func rpcSetWakeOnLanDevices(params SetWakeOnLanDevicesParams) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func rpcResetConfig() error {
|
func rpcResetConfig() error {
|
||||||
config = defaultConfig
|
defaultConfig := getDefaultConfig()
|
||||||
|
config = &defaultConfig
|
||||||
if err := SaveConfig(); err != nil {
|
if err := SaveConfig(); err != nil {
|
||||||
return fmt.Errorf("failed to reset config: %w", err)
|
return fmt.Errorf("failed to reset config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue