mirror of https://github.com/jetkvm/kvm.git
				
				
				
			added slug dependency
device name slugified to dns name when set
This commit is contained in:
		
							parent
							
								
									84c8018ff9
								
							
						
					
					
						commit
						fa01d7c828
					
				| 
						 | 
				
			
			@ -26,6 +26,7 @@ type Config struct {
 | 
			
		|||
	EdidString           string            `json:"hdmi_edid_string"`
 | 
			
		||||
	ActiveExtension      string            `json:"active_extension"`
 | 
			
		||||
	DeviceName           string            `json:"device_name"`
 | 
			
		||||
	DNSName              string            `json:"dns_name"`
 | 
			
		||||
	DisplayMaxBrightness int               `json:"display_max_brightness"`
 | 
			
		||||
	DisplayDimAfterSec   int               `json:"display_dim_after_sec"`
 | 
			
		||||
	DisplayOffAfterSec   int               `json:"display_off_after_sec"`
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +39,7 @@ var defaultConfig = &Config{
 | 
			
		|||
	AutoUpdateEnabled:    true, // Set a default value
 | 
			
		||||
	ActiveExtension:      "",
 | 
			
		||||
	DeviceName:           "JetKVM",
 | 
			
		||||
	DNSName:              "jetkvm.local",
 | 
			
		||||
	DisplayMaxBrightness: 64,
 | 
			
		||||
	DisplayDimAfterSec:   120,  // 2 minutes
 | 
			
		||||
	DisplayOffAfterSec:   1800, // 30 minutes
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										2
									
								
								go.mod
								
								
								
								
							| 
						 | 
				
			
			@ -42,6 +42,8 @@ require (
 | 
			
		|||
	github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
			
		||||
	github.com/go-playground/validator/v10 v10.20.0 // indirect
 | 
			
		||||
	github.com/goccy/go-json v0.10.2 // indirect
 | 
			
		||||
	github.com/gosimple/slug v1.15.0 // indirect
 | 
			
		||||
	github.com/gosimple/unidecode v1.0.1 // indirect
 | 
			
		||||
	github.com/json-iterator/go v1.1.12 // indirect
 | 
			
		||||
	github.com/klauspost/cpuid/v2 v2.2.7 // indirect
 | 
			
		||||
	github.com/kr/pretty v0.3.0 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								go.sum
								
								
								
								
							
							
						
						
									
										4
									
								
								go.sum
								
								
								
								
							| 
						 | 
				
			
			@ -47,6 +47,10 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
 | 
			
		|||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
			
		||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
			
		||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
			
		||||
github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo=
 | 
			
		||||
github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
 | 
			
		||||
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
 | 
			
		||||
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
 | 
			
		||||
github.com/gwatts/rootcerts v0.0.0-20240401182218-3ab9db955caf h1:JO6ISZIvEUitto5zjQ3/VEnDM5rPbqIFuOhS0U0ByeA=
 | 
			
		||||
github.com/gwatts/rootcerts v0.0.0-20240401182218-3ab9db955caf/go.mod h1:5Kt9XkWvkGi2OHOq0QsGxebHmhCcqJ8KCbNg/a6+n+g=
 | 
			
		||||
github.com/hanwen/go-fuse/v2 v2.5.1 h1:OQBE8zVemSocRxA4OaFJbjJ5hlpCmIWbGr7r0M4uoQQ=
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ import (
 | 
			
		|||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/gosimple/slug"
 | 
			
		||||
	"github.com/pion/webrtc/v4"
 | 
			
		||||
	"go.bug.st/serial"
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -301,13 +302,14 @@ func rpcGetDeviceName() (string, error) {
 | 
			
		|||
func rpcSetDeviceName(deviceName string) error {
 | 
			
		||||
	LoadConfig()
 | 
			
		||||
	config.DeviceName = deviceName
 | 
			
		||||
	config.DNSName = slug.Make(deviceName)
 | 
			
		||||
 | 
			
		||||
	err := SaveConfig()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("failed to save device name: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Printf("[jsonrpc.go:rpcSetDeviceName] device name set to %s", deviceName)
 | 
			
		||||
	log.Printf("[jsonrpc.go:rpcSetDeviceName] device name set to %s, dns name set to %s", config.DeviceName, config.DNSName)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -124,7 +124,9 @@ func startMDNS() error {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	// Start a new server
 | 
			
		||||
	fmt.Printf("Starting mDNS server on jetkvm.local\n")
 | 
			
		||||
	//fmt.Printf("Starting mDNS server on jetkvm.local\n")
 | 
			
		||||
	LoadConfig()
 | 
			
		||||
	fmt.Printf("Starting mDNS server on %v\n", config.DNSName)
 | 
			
		||||
	addr4, err := net.ResolveUDPAddr("udp4", mdns.DefaultAddressIPv4)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
| 
						 | 
				
			
			@ -146,7 +148,8 @@ func startMDNS() error {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	mDNSConn, err = mdns.Server(ipv4.NewPacketConn(l4), ipv6.NewPacketConn(l6), &mdns.Config{
 | 
			
		||||
		LocalNames: []string{"jetkvm.local"}, //TODO: make it configurable
 | 
			
		||||
		LocalNames: []string{config.DNSName},
 | 
			
		||||
		//LocalNames: []string{"jetkvm.local"}, //TODO: make it configurable
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		mDNSConn = nil
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue