mirror of https://github.com/jetkvm/kvm.git
				
				
				
			Compare commits
	
		
			6 Commits
		
	
	
		
			382c07b87a
			...
			58c5875aa7
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | 58c5875aa7 | |
|  | 682b5911e8 | |
|  | 621c333041 | |
|  | 313f78000e | |
|  | 6a6ab143a8 | |
|  | bffac9a6b5 | 
							
								
								
									
										20
									
								
								config.go
								
								
								
								
							
							
						
						
									
										20
									
								
								config.go
								
								
								
								
							|  | @ -12,11 +12,11 @@ type WakeOnLanDevice struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type UsbConfig struct { | type UsbConfig struct { | ||||||
| 	UsbVendorId     string `json:"usb_vendor_id"` | 	VendorId     string `json:"vendor_id"` | ||||||
| 	UsbProductId    string `json:"usb_product_id"` | 	ProductId    string `json:"product_id"` | ||||||
| 	UsbSerialNumber string `json:"usb_serial_number"` | 	SerialNumber string `json:"serial_number"` | ||||||
| 	UsbManufacturer string `json:"usb_manufacturer"` | 	Manufacturer string `json:"manufacturer"` | ||||||
| 	UsbProduct      string `json:"usb_product"` | 	Product      string `json:"product"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Config struct { | type Config struct { | ||||||
|  | @ -39,11 +39,11 @@ var defaultConfig = &Config{ | ||||||
| 	CloudURL:          "https://api.jetkvm.com", | 	CloudURL:          "https://api.jetkvm.com", | ||||||
| 	AutoUpdateEnabled: true, // Set a default value
 | 	AutoUpdateEnabled: true, // Set a default value
 | ||||||
| 	UsbConfig: UsbConfig{ | 	UsbConfig: UsbConfig{ | ||||||
| 		UsbVendorId:     "0x1d6b", //The Linux Foundation
 | 		VendorId:     "0x1d6b", //The Linux Foundation
 | ||||||
| 		UsbProductId:    "0x0104", //Multifunction Composite Gadget¬
 | 		ProductId:    "0x0104", //Multifunction Composite Gadget¬
 | ||||||
| 		UsbSerialNumber: "", | 		SerialNumber: "", | ||||||
| 		UsbManufacturer: "JetKVM", | 		Manufacturer: "JetKVM", | ||||||
| 		UsbProduct:      "JetKVM USB Emulation Device", | 		Product:      "JetKVM USB Emulation Device", | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ export interface UsbConfigState { | ||||||
|   product_id: string; |   product_id: string; | ||||||
|   serial_number: string; |   serial_number: string; | ||||||
|   manufacturer: string; |   manufacturer: string; | ||||||
|   product_name: string; |   product: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default function USBConfigDialog({ | export default function USBConfigDialog({ | ||||||
|  | @ -79,11 +79,11 @@ function UpdateUsbConfigModal({ | ||||||
|   error: string | null; |   error: string | null; | ||||||
| }) { | }) { | ||||||
|   const [usbConfig, setUsbConfig] = useState({ |   const [usbConfig, setUsbConfig] = useState({ | ||||||
|     usb_vendor_id: '', |     vendor_id: '', | ||||||
|     usb_product_id: '', |     product_id: '', | ||||||
|     usb_serial_number: '', |     serial_number: '', | ||||||
|     usb_manufacturer: '', |     manufacturer: '', | ||||||
|     usb_product: '', |     product: '', | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|   const [usbConfigState, setUsbConfigState] = useState<UsbConfigState>(); |   const [usbConfigState, setUsbConfigState] = useState<UsbConfigState>(); | ||||||
|  | @ -91,11 +91,10 @@ function UpdateUsbConfigModal({ | ||||||
| 
 | 
 | ||||||
|   const syncUsbConfig = useCallback(() => { |   const syncUsbConfig = useCallback(() => { | ||||||
|     send("getUsbConfig", {}, resp => { |     send("getUsbConfig", {}, resp => { | ||||||
|       if ("result" in resp) { |       if ("error" in resp) { | ||||||
|         console.info("Successfully synced USB Config: ", resp.result); |  | ||||||
|         setUsbConfigState(resp.result as UsbConfigState); |  | ||||||
|       } else { |  | ||||||
|         console.error("Failed to load USB Config:", resp.error); |         console.error("Failed to load USB Config:", resp.error); | ||||||
|  |       } else { | ||||||
|  |         setUsbConfigState(resp.result as UsbConfigState); | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   }, [send, setUsbConfigState]); |   }, [send, setUsbConfigState]); | ||||||
|  | @ -105,24 +104,24 @@ function UpdateUsbConfigModal({ | ||||||
|     syncUsbConfig(); |     syncUsbConfig(); | ||||||
|   }, [syncUsbConfig]); |   }, [syncUsbConfig]); | ||||||
| 
 | 
 | ||||||
|   const handleUsbVendorIdChange = (vendorId: string) => { |   const handleUsbVendorIdChange = (value: string) => { | ||||||
|     setUsbConfig({... usbConfig, usb_vendor_id: vendorId}) |     setUsbConfig({... usbConfig, vendor_id: value}) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const handleUsbProductIdChange = (productId: string) => { |   const handleUsbProductIdChange = (value: string) => { | ||||||
|     setUsbConfig({... usbConfig, usb_product_id: productId}) |     setUsbConfig({... usbConfig, product_id: value}) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const handleUsbSerialChange = (serialNumber: string) => { |   const handleUsbSerialChange = (value: string) => { | ||||||
|     setUsbConfig({... usbConfig, usb_serial_number: serialNumber}) |     setUsbConfig({... usbConfig, serial_number: value}) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const handleUsbManufacturer = (manufacturer: string) => { |   const handleUsbManufacturer = (value: string) => { | ||||||
|     setUsbConfig({... usbConfig, usb_manufacturer: manufacturer}) |     setUsbConfig({... usbConfig, manufacturer: value}) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const handleUsbProduct = (name: string) => { |   const handleUsbProduct = (value: string) => { | ||||||
|     setUsbConfig({... usbConfig, usb_product: name}) |     setUsbConfig({... usbConfig, product: value}) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|  | @ -143,35 +142,37 @@ function UpdateUsbConfigModal({ | ||||||
|           required |           required | ||||||
|           label="Vendor ID" |           label="Vendor ID" | ||||||
|           placeholder="Enter Vendor ID" |           placeholder="Enter Vendor ID" | ||||||
|           value={usbConfigState?.vendor_id} |           pattern="^0[xX][\da-fA-F]{4}$" | ||||||
|  |           defaultValue={usbConfigState?.vendor_id} | ||||||
|           onChange={e => handleUsbVendorIdChange(e.target.value)} |           onChange={e => handleUsbVendorIdChange(e.target.value)} | ||||||
|         /> |         /> | ||||||
|         <InputFieldWithLabel |         <InputFieldWithLabel | ||||||
|           required |           required | ||||||
|           label="Product ID" |           label="Product ID" | ||||||
|           placeholder="Enter Product ID" |           placeholder="Enter Product ID" | ||||||
|           value={usbConfigState?.product_id} |           pattern="^0[xX][\da-fA-F]{4}$" | ||||||
|  |           defaultValue={usbConfigState?.product_id} | ||||||
|           onChange={e => handleUsbProductIdChange(e.target.value)} |           onChange={e => handleUsbProductIdChange(e.target.value)} | ||||||
|         /> |         /> | ||||||
|         <InputFieldWithLabel |         <InputFieldWithLabel | ||||||
|           required |           required | ||||||
|           label="Serial Number" |           label="Serial Number" | ||||||
|           placeholder="Enter Serial Number" |           placeholder="Enter Serial Number" | ||||||
|           value={usbConfigState?.serial_number} |           defaultValue={usbConfigState?.serial_number} | ||||||
|           onChange={e => handleUsbSerialChange(e.target.value)} |           onChange={e => handleUsbSerialChange(e.target.value)} | ||||||
|         /> |         /> | ||||||
|         <InputFieldWithLabel |         <InputFieldWithLabel | ||||||
|           required |           required | ||||||
|           label="Manufacturer" |           label="Manufacturer" | ||||||
|           placeholder="Enter Manufacturer" |           placeholder="Enter Manufacturer" | ||||||
|           value={usbConfigState?.manufacturer} |           defaultValue={usbConfigState?.manufacturer} | ||||||
|           onChange={e => handleUsbManufacturer(e.target.value)} |           onChange={e => handleUsbManufacturer(e.target.value)} | ||||||
|         /> |         /> | ||||||
|         <InputFieldWithLabel |         <InputFieldWithLabel | ||||||
|           required |           required | ||||||
|           label="Product Name" |           label="Product Name" | ||||||
|           placeholder="Enter Product Name" |           placeholder="Enter Product Name" | ||||||
|           value={usbConfigState?.product_name} |           defaultValue={usbConfigState?.product} | ||||||
|           onChange={e => handleUsbProduct(e.target.value)} |           onChange={e => handleUsbProduct(e.target.value)} | ||||||
|         /> |         /> | ||||||
|         <div className="flex gap-x-2"> |         <div className="flex gap-x-2"> | ||||||
|  |  | ||||||
							
								
								
									
										18
									
								
								usb.go
								
								
								
								
							
							
						
						
									
										18
									
								
								usb.go
								
								
								
								
							|  | @ -61,8 +61,8 @@ func init() { | ||||||
| func UpdateGadgetConfig() error { | func UpdateGadgetConfig() error { | ||||||
| 	LoadConfig() | 	LoadConfig() | ||||||
| 	gadgetAttrs := [][]string{ | 	gadgetAttrs := [][]string{ | ||||||
| 		{"idVendor", config.UsbConfig.UsbVendorId}, | 		{"idVendor", config.UsbConfig.VendorId}, | ||||||
| 		{"idProduct", config.UsbConfig.UsbProductId}, | 		{"idProduct", config.UsbConfig.ProductId}, | ||||||
| 	} | 	} | ||||||
| 	err := writeGadgetAttrs(kvmGadgetPath, gadgetAttrs) | 	err := writeGadgetAttrs(kvmGadgetPath, gadgetAttrs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | @ -72,9 +72,9 @@ func UpdateGadgetConfig() error { | ||||||
| 	log.Printf("Successfully updated usb gadget attributes: %v", gadgetAttrs) | 	log.Printf("Successfully updated usb gadget attributes: %v", gadgetAttrs) | ||||||
| 
 | 
 | ||||||
| 	strAttrs := [][]string{ | 	strAttrs := [][]string{ | ||||||
| 		{"serialnumber", config.UsbConfig.UsbSerialNumber}, | 		{"serialnumber", config.UsbConfig.SerialNumber}, | ||||||
| 		{"manufacturer", config.UsbConfig.UsbManufacturer}, | 		{"manufacturer", config.UsbConfig.Manufacturer}, | ||||||
| 		{"product", config.UsbConfig.UsbProduct}, | 		{"product", config.UsbConfig.Product}, | ||||||
| 	} | 	} | ||||||
| 	gadgetStringsPath := filepath.Join(kvmGadgetPath, "strings", "0x409") | 	gadgetStringsPath := filepath.Join(kvmGadgetPath, "strings", "0x409") | ||||||
| 	err = os.MkdirAll(gadgetStringsPath, 0755) | 	err = os.MkdirAll(gadgetStringsPath, 0755) | ||||||
|  | @ -120,8 +120,8 @@ func writeGadgetConfig() error { | ||||||
| 	LoadConfig() | 	LoadConfig() | ||||||
| 	err = writeGadgetAttrs(kvmGadgetPath, [][]string{ | 	err = writeGadgetAttrs(kvmGadgetPath, [][]string{ | ||||||
| 		{"bcdUSB", "0x0200"}, //USB 2.0
 | 		{"bcdUSB", "0x0200"}, //USB 2.0
 | ||||||
| 		{"idVendor", config.UsbConfig.UsbVendorId}, | 		{"idVendor", config.UsbConfig.VendorId}, | ||||||
| 		{"idProduct", config.UsbConfig.UsbProductId}, | 		{"idProduct", config.UsbConfig.ProductId}, | ||||||
| 		{"bcdDevice", "0100"}, | 		{"bcdDevice", "0100"}, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | @ -136,8 +136,8 @@ func writeGadgetConfig() error { | ||||||
| 
 | 
 | ||||||
| 	err = writeGadgetAttrs(gadgetStringsPath, [][]string{ | 	err = writeGadgetAttrs(gadgetStringsPath, [][]string{ | ||||||
| 		{"serialnumber", GetDeviceID()}, | 		{"serialnumber", GetDeviceID()}, | ||||||
| 		{"manufacturer", config.UsbConfig.UsbManufacturer}, | 		{"manufacturer", config.UsbConfig.Manufacturer}, | ||||||
| 		{"product", config.UsbConfig.UsbProduct}, | 		{"product", config.UsbConfig.Product}, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue