mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
Complete local Bose SoundTouch emulation service with guided migration UI
This commit is contained in:
@@ -270,6 +270,7 @@ func setupRouter(server *handlers.Server, pyProxy *httputil.ReverseProxy) *chi.M
|
||||
|
||||
r.Route("/setup", func(r chi.Router) {
|
||||
r.Get("/devices", server.HandleListDiscoveredDevices)
|
||||
r.Post("/devices", server.HandleAddManualDevice)
|
||||
r.Post("/discover", server.HandleTriggerDiscovery)
|
||||
r.Get("/discovery-status", server.HandleGetDiscoveryStatus)
|
||||
r.Get("/settings", server.HandleGetSettings)
|
||||
@@ -280,6 +281,7 @@ func setupRouter(server *handlers.Server, pyProxy *httputil.ReverseProxy) *chi.M
|
||||
r.Post("/ensure-remote-services/{deviceIP}", server.HandleEnsureRemoteServices)
|
||||
r.Post("/remove-remote-services/{deviceIP}", server.HandleRemoveRemoteServices)
|
||||
r.Post("/backup/{deviceIP}", server.HandleBackupConfig)
|
||||
r.Post("/sync/{deviceIP}", server.HandleInitialSync)
|
||||
r.Post("/test-connection/{deviceIP}", server.HandleTestConnection)
|
||||
r.Post("/test-hosts/{deviceIP}", server.HandleTestHostsRedirection)
|
||||
r.Get("/ca.crt", server.HandleGetCACert)
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
### Bose Cloud Shutdown: Survival Guide for SoundTouch
|
||||
|
||||
With Bose's announcement of discontinuing cloud support for SoundTouch devices in May 2026, this project provides the necessary tools to keep your speakers fully functional using a local emulation service.
|
||||
|
||||
This guide explains how to set up the `soundtouch-service` to run your devices independently of Bose's servers.
|
||||
|
||||
---
|
||||
|
||||
### Supported Use Cases
|
||||
|
||||
1. **Local Service Emulation**: The service emulates Bose's BMX (Bose Media eXchange) and Marge services, which handle content registries, presets, recents, and software update checks.
|
||||
2. **Traffic Redirection**: Tools are provided to redirect your speakers to this local service instead of `*.bose.com`.
|
||||
3. **Offline Operation**: Once redirected, the speakers function without needing to reach Bose's servers.
|
||||
4. **Preset & Recent Management**: Captures and stores presets and "recently played" items locally.
|
||||
|
||||
---
|
||||
|
||||
### Setup Steps
|
||||
|
||||
To set up your SoundTouch system for local-only operation, follow these steps:
|
||||
|
||||
#### 1. Install and Start the Service
|
||||
Run the `soundtouch-service` on a machine that is always on (like a Raspberry Pi or a NAS) within your local network.
|
||||
|
||||
```bash
|
||||
# Install the service
|
||||
go install github.com/gesellix/bose-soundtouch/cmd/soundtouch-service@latest
|
||||
|
||||
# Start the service (defaults to http://localhost:8000)
|
||||
soundtouch-service
|
||||
```
|
||||
|
||||
#### 2. Access the Management UI
|
||||
Open your web browser and navigate to the service's web interface:
|
||||
`http://<your-server-ip>:8000/`, e.g. `http://localhost:8000/`
|
||||
|
||||
*Note: The service also supports a `/web/` path for management.*
|
||||
|
||||
#### 3. Enable SSH on Your Speakers
|
||||
To migrate your speakers, the service needs SSH access. You can enable it by:
|
||||
1. Creating an empty file named `remote_services` on a USB stick.
|
||||
2. Inserting the USB stick into the SoundTouch speaker's service port.
|
||||
3. Rebooting the speaker.
|
||||
Once enabled, you can log in as `root` (no password).
|
||||
|
||||
#### 4. Discover and Sync Device Data
|
||||
The web interface handles the entire process in a guided flow across four tabs:
|
||||
|
||||
* **Step 1: Devices**: The service automatically scans for SoundTouch devices on your network. If a device is not found, you can manually add its IP address.
|
||||
* **Step 2: Data Sync**: Select your device and click "Start Sync". This will automatically fetch your presets, recents, and configured sources from the speaker and store them in the local `data/` directory.
|
||||
* **Step 3: Migration**: Choose your redirection method (XML Recommended) and click "Confirm Migration & Reboot".
|
||||
* **Step 4: Settings**: Configure global server URLs and proxy behavior (logging, redaction).
|
||||
|
||||
#### 5. Verify Your Local Data
|
||||
Once migrated, your speaker will use the data captured during the Sync step.
|
||||
* The service stores data in the `data/` directory, organized by device serial number (e.g., `data/default/devices/<SERIAL>/`).
|
||||
* **Automatic Capture**: As you use the device (changing presets, playing new music), the service continues to "learn" and update your local files.
|
||||
|
||||
---
|
||||
|
||||
### Comparison with other implementations (soundcork)
|
||||
Our implementation (`soundtouch-service`) is largely compatible with the Python-based `soundcork` project but offers several advantages:
|
||||
- **Web UI**: Integrated management interface for discovery and migration.
|
||||
- **Surgical Migration**: Uses XML-based redirection by default, which is less invasive than `/etc/hosts`.
|
||||
- **Automated SSL**: Handles Root CA injection automatically for secure communication.
|
||||
- **Proxy Support**: Can proxy requests to original Bose servers while "learning" your configuration.
|
||||
|
||||
---
|
||||
|
||||
### Alternative: DNS Redirection (No SSH)
|
||||
If you prefer not to modify your speakers via SSH, you can use a local DNS server (like Pi-hole, AdGuard Home, or Unbound) to point the following domains to your local server's IP:
|
||||
|
||||
* `bmx.bose.com`
|
||||
* `streaming.bose.com`
|
||||
* `updates.bose.com`
|
||||
* `stats.bose.com`
|
||||
* `content.api.bose.io`
|
||||
|
||||
*Note: DNS redirection for HTTPS services requires the speakers to trust your local service's SSL certificate. The SSH-based migration handles this automatically by injecting the CA.*
|
||||
|
||||
---
|
||||
+14
-6
@@ -160,12 +160,19 @@ type ServiceRecent struct {
|
||||
|
||||
// ConfiguredSource represents a configured media source with authentication details.
|
||||
type ConfiguredSource struct {
|
||||
DisplayName string `json:"display_name" xml:"sourcename"`
|
||||
ID string `json:"id" xml:"id,attr"`
|
||||
Secret string `json:"secret" xml:"credential"`
|
||||
SecretType string `json:"secret_type" xml:"credential_type,attr"`
|
||||
SourceKeyType string `json:"source_key_type" xml:"sourceproviderid"`
|
||||
SourceKeyAccount string `json:"source_key_account" xml:"username"`
|
||||
DisplayName string `json:"display_name" xml:"displayName,attr"`
|
||||
ID string `json:"id" xml:"id,attr"`
|
||||
Secret string `json:"secret" xml:"secret,attr"`
|
||||
SecretType string `json:"secret_type" xml:"secretType,attr"`
|
||||
SourceKey struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Account string `xml:"account,attr"`
|
||||
} `json:"source_key" xml:"sourceKey"`
|
||||
|
||||
// Legacy fields for backward compatibility in code if needed,
|
||||
// though it's better to update the code to use SourceKey.
|
||||
SourceKeyType string `json:"source_key_type" xml:"-"`
|
||||
SourceKeyAccount string `json:"source_key_account" xml:"-"`
|
||||
}
|
||||
|
||||
// ServiceDeviceInfo represents information about a SoundTouch device.
|
||||
@@ -177,6 +184,7 @@ type ServiceDeviceInfo struct {
|
||||
FirmwareVersion string `json:"firmware_version" xml:"softwareVersion"`
|
||||
IPAddress string `json:"ip_address" xml:"ipAddress"`
|
||||
Name string `json:"name" xml:"name"`
|
||||
DiscoveryMethod string `json:"discovery_method,omitempty"`
|
||||
}
|
||||
|
||||
// CustomerSupportDevice represents device information for customer support purposes.
|
||||
|
||||
@@ -132,7 +132,9 @@ func (ds *DataStore) ListAllDevices() ([]models.ServiceDeviceInfo, error) {
|
||||
}
|
||||
|
||||
accDevices := ds.listDevicesInAccount(dir, acc.Name())
|
||||
for _, info := range accDevices {
|
||||
for i := range accDevices {
|
||||
info := accDevices[i]
|
||||
|
||||
key := info.DeviceID
|
||||
if key == "" {
|
||||
key = info.IPAddress
|
||||
@@ -219,6 +221,7 @@ func (ds *DataStore) parseDeviceInfoFile(path string) (*models.ServiceDeviceInfo
|
||||
Type string `xml:"type,attr"`
|
||||
IPAddress string `xml:"ipAddress"`
|
||||
} `xml:"networkInfo"`
|
||||
DiscoveryMethod string `xml:"discoveryMethod"`
|
||||
}
|
||||
|
||||
if err := xml.Unmarshal(data, &info); err != nil {
|
||||
@@ -226,9 +229,10 @@ func (ds *DataStore) parseDeviceInfoFile(path string) (*models.ServiceDeviceInfo
|
||||
}
|
||||
|
||||
deviceInfo := &models.ServiceDeviceInfo{
|
||||
DeviceID: info.DeviceID,
|
||||
ProductCode: fmt.Sprintf("%s %s", info.Type, info.ModuleType),
|
||||
Name: info.Name,
|
||||
DeviceID: info.DeviceID,
|
||||
ProductCode: fmt.Sprintf("%s %s", info.Type, info.ModuleType),
|
||||
Name: info.Name,
|
||||
DiscoveryMethod: info.DiscoveryMethod,
|
||||
}
|
||||
|
||||
for _, comp := range info.Components {
|
||||
@@ -250,9 +254,9 @@ func (ds *DataStore) parseDeviceInfoFile(path string) (*models.ServiceDeviceInfo
|
||||
return deviceInfo, nil
|
||||
}
|
||||
|
||||
// GetPresets retrieves all presets for the specified account.
|
||||
func (ds *DataStore) GetPresets(account string) ([]models.ServicePreset, error) {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.PresetsFile)
|
||||
// GetPresets retrieves all presets for the specified account and device.
|
||||
func (ds *DataStore) GetPresets(account, device string) ([]models.ServicePreset, error) {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.PresetsFile)
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -303,9 +307,9 @@ func (ds *DataStore) GetPresets(account string) ([]models.ServicePreset, error)
|
||||
return presets, nil
|
||||
}
|
||||
|
||||
// SavePresets saves the preset list for the specified account.
|
||||
func (ds *DataStore) SavePresets(account string, presets []models.ServicePreset) error {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.PresetsFile)
|
||||
// SavePresets saves the preset list for the specified account and device.
|
||||
func (ds *DataStore) SavePresets(account, device string, presets []models.ServicePreset) error {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.PresetsFile)
|
||||
|
||||
type PresetXML struct {
|
||||
ID string `xml:"id,attr"`
|
||||
@@ -357,9 +361,9 @@ func (ds *DataStore) SavePresets(account string, presets []models.ServicePreset)
|
||||
return os.WriteFile(path, append(header, data...), 0644)
|
||||
}
|
||||
|
||||
// GetRecents retrieves all recent items for the specified account.
|
||||
func (ds *DataStore) GetRecents(account string) ([]models.ServiceRecent, error) {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.RecentsFile)
|
||||
// GetRecents retrieves all recent items for the specified account and device.
|
||||
func (ds *DataStore) GetRecents(account, device string) ([]models.ServiceRecent, error) {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.RecentsFile)
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -410,9 +414,9 @@ func (ds *DataStore) GetRecents(account string) ([]models.ServiceRecent, error)
|
||||
return recents, nil
|
||||
}
|
||||
|
||||
// SaveRecents saves the recent items list for the specified account.
|
||||
func (ds *DataStore) SaveRecents(account string, recents []models.ServiceRecent) error {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.RecentsFile)
|
||||
// SaveRecents saves the recent items list for the specified account and device.
|
||||
func (ds *DataStore) SaveRecents(account, device string, recents []models.ServiceRecent) error {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.RecentsFile)
|
||||
|
||||
type RecentXML struct {
|
||||
ID string `xml:"id,attr"`
|
||||
@@ -494,13 +498,14 @@ func (ds *DataStore) SaveDeviceInfo(account, device string, info *models.Service
|
||||
}
|
||||
|
||||
type InfoXML struct {
|
||||
XMLName xml.Name `xml:"info"`
|
||||
DeviceID string `xml:"deviceID,attr"`
|
||||
Name string `xml:"name"`
|
||||
Type string `xml:"type"`
|
||||
ModuleType string `xml:"moduleType"`
|
||||
Components []ComponentXML `xml:"components>component"`
|
||||
NetworkInfo []NetworkInfoXML `xml:"networkInfo"`
|
||||
XMLName xml.Name `xml:"info"`
|
||||
DeviceID string `xml:"deviceID,attr"`
|
||||
Name string `xml:"name"`
|
||||
Type string `xml:"type"`
|
||||
ModuleType string `xml:"moduleType"`
|
||||
Components []ComponentXML `xml:"components>component"`
|
||||
NetworkInfo []NetworkInfoXML `xml:"networkInfo"`
|
||||
DiscoveryMethod string `xml:"discoveryMethod,omitempty"`
|
||||
}
|
||||
|
||||
// Parsing product code back to type and moduleType (best effort)
|
||||
@@ -539,6 +544,7 @@ func (ds *DataStore) SaveDeviceInfo(account, device string, info *models.Service
|
||||
IPAddress: info.IPAddress,
|
||||
},
|
||||
},
|
||||
DiscoveryMethod: info.DiscoveryMethod,
|
||||
}
|
||||
|
||||
data, err := xml.MarshalIndent(ix, "", " ")
|
||||
@@ -557,9 +563,9 @@ func (ds *DataStore) RemoveDevice(account, device string) error {
|
||||
return os.RemoveAll(dir)
|
||||
}
|
||||
|
||||
// GetConfiguredSources retrieves all configured sources for the specified account.
|
||||
func (ds *DataStore) GetConfiguredSources(account string) ([]models.ConfiguredSource, error) {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.SourcesFile)
|
||||
// GetConfiguredSources retrieves all configured sources for the specified account and device.
|
||||
func (ds *DataStore) GetConfiguredSources(account, device string) ([]models.ConfiguredSource, error) {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.SourcesFile)
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -567,81 +573,52 @@ func (ds *DataStore) GetConfiguredSources(account string) ([]models.ConfiguredSo
|
||||
}
|
||||
|
||||
var sourcesWrap struct {
|
||||
Sources []struct {
|
||||
DisplayName string `xml:"displayName,attr"`
|
||||
ID string `xml:"id,attr"`
|
||||
Secret string `xml:"secret,attr"`
|
||||
SecretType string `xml:"secretType,attr"`
|
||||
SourceKey struct {
|
||||
Account string `xml:"account,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
} `xml:"sourceKey"`
|
||||
} `xml:"source"`
|
||||
Sources []models.ConfiguredSource `xml:"source"`
|
||||
}
|
||||
|
||||
if err := xml.Unmarshal(data, &sourcesWrap); err != nil {
|
||||
return nil, fmt.Errorf("malformed sources XML at %s: %w", path, err)
|
||||
}
|
||||
|
||||
var sources []models.ConfiguredSource
|
||||
|
||||
lastID := 100001
|
||||
|
||||
for _, s := range sourcesWrap.Sources {
|
||||
id := s.ID
|
||||
if id == "" {
|
||||
id = strconv.Itoa(lastID)
|
||||
lastID++
|
||||
for i := range sourcesWrap.Sources {
|
||||
s := &sourcesWrap.Sources[i]
|
||||
if s.ID == "" {
|
||||
s.ID = strconv.Itoa(100001 + i)
|
||||
}
|
||||
|
||||
sources = append(sources, models.ConfiguredSource{
|
||||
DisplayName: s.DisplayName,
|
||||
ID: id,
|
||||
Secret: s.Secret,
|
||||
SecretType: s.SecretType,
|
||||
SourceKeyType: s.SourceKey.Type,
|
||||
SourceKeyAccount: s.SourceKey.Account,
|
||||
})
|
||||
// Sync legacy fields
|
||||
s.SourceKeyType = s.SourceKey.Type
|
||||
s.SourceKeyAccount = s.SourceKey.Account
|
||||
}
|
||||
|
||||
return sources, nil
|
||||
return sourcesWrap.Sources, nil
|
||||
}
|
||||
|
||||
// SaveConfiguredSources saves the configured sources list for the specified account.
|
||||
func (ds *DataStore) SaveConfiguredSources(account string, sources []models.ConfiguredSource) error {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.SourcesFile)
|
||||
// SaveConfiguredSources saves the configured sources list for the specified account and device.
|
||||
func (ds *DataStore) SaveConfiguredSources(account, device string, sources []models.ConfiguredSource) error {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.SourcesFile)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
type sourceXML struct {
|
||||
DisplayName string `xml:"displayName,attr"`
|
||||
ID string `xml:"id,attr"`
|
||||
Secret string `xml:"secret,attr"`
|
||||
SecretType string `xml:"secretType,attr"`
|
||||
SourceKey struct {
|
||||
Account string `xml:"account,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
} `xml:"sourceKey"`
|
||||
}
|
||||
|
||||
type sourcesWrap struct {
|
||||
XMLName xml.Name `xml:"sources"`
|
||||
Sources []sourceXML `xml:"source"`
|
||||
XMLName xml.Name `xml:"sources"`
|
||||
Sources []models.ConfiguredSource `xml:"source"`
|
||||
}
|
||||
|
||||
wrap := sourcesWrap{}
|
||||
|
||||
for _, s := range sources {
|
||||
sx := sourceXML{
|
||||
DisplayName: s.DisplayName,
|
||||
ID: s.ID,
|
||||
Secret: s.Secret,
|
||||
SecretType: s.SecretType,
|
||||
// Ensure SourceKey is populated from legacy fields if necessary before saving
|
||||
for i := range sources {
|
||||
s := &sources[i]
|
||||
if s.SourceKey.Type == "" && s.SourceKeyType != "" {
|
||||
s.SourceKey.Type = s.SourceKeyType
|
||||
}
|
||||
sx.SourceKey.Account = s.SourceKeyAccount
|
||||
sx.SourceKey.Type = s.SourceKeyType
|
||||
wrap.Sources = append(wrap.Sources, sx)
|
||||
|
||||
if s.SourceKey.Account == "" && s.SourceKeyAccount != "" {
|
||||
s.SourceKey.Account = s.SourceKeyAccount
|
||||
}
|
||||
}
|
||||
|
||||
wrap := sourcesWrap{
|
||||
Sources: sources,
|
||||
}
|
||||
|
||||
data, err := xml.MarshalIndent(wrap, "", " ")
|
||||
@@ -675,9 +652,9 @@ func (ds *DataStore) Initialize() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetETagForPresets returns the ETag (modification time) for the presets file.
|
||||
func (ds *DataStore) GetETagForPresets(account string) int64 {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.PresetsFile)
|
||||
// GetETagForPresets returns the ETag (modification time) for the presets file for a specific device.
|
||||
func (ds *DataStore) GetETagForPresets(account, device string) int64 {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.PresetsFile)
|
||||
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@@ -687,9 +664,9 @@ func (ds *DataStore) GetETagForPresets(account string) int64 {
|
||||
return info.ModTime().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// GetETagForSources returns the ETag (modification time) for the sources file.
|
||||
func (ds *DataStore) GetETagForSources(account string) int64 {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.SourcesFile)
|
||||
// GetETagForSources returns the ETag (modification time) for the sources file for a specific device.
|
||||
func (ds *DataStore) GetETagForSources(account, device string) int64 {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.SourcesFile)
|
||||
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@@ -699,9 +676,9 @@ func (ds *DataStore) GetETagForSources(account string) int64 {
|
||||
return info.ModTime().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// GetETagForRecents returns the ETag (modification time) for the recents file.
|
||||
func (ds *DataStore) GetETagForRecents(account string) int64 {
|
||||
path := filepath.Join(ds.AccountDir(account), constants.RecentsFile)
|
||||
// GetETagForRecents returns the ETag (modification time) for the recents file for a specific device.
|
||||
func (ds *DataStore) GetETagForRecents(account, device string) int64 {
|
||||
path := filepath.Join(ds.AccountDeviceDir(account, device), constants.RecentsFile)
|
||||
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@@ -711,11 +688,11 @@ func (ds *DataStore) GetETagForRecents(account string) int64 {
|
||||
return info.ModTime().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// GetETagForAccount returns the highest ETag among presets, sources, and recents for the account.
|
||||
func (ds *DataStore) GetETagForAccount(account string) int64 {
|
||||
e1 := ds.GetETagForPresets(account)
|
||||
e2 := ds.GetETagForSources(account)
|
||||
e3 := ds.GetETagForRecents(account)
|
||||
// GetETagForAccount returns the highest ETag among presets, sources, and recents for the account and device.
|
||||
func (ds *DataStore) GetETagForAccount(account, device string) int64 {
|
||||
e1 := ds.GetETagForPresets(account, device)
|
||||
e2 := ds.GetETagForSources(account, device)
|
||||
e3 := ds.GetETagForRecents(account, device)
|
||||
|
||||
maxETag := e1
|
||||
if e2 > maxETag {
|
||||
|
||||
@@ -49,12 +49,12 @@ func TestDataStore(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = ds.SavePresets(account, presets)
|
||||
err = ds.SavePresets(account, device, presets)
|
||||
if err != nil {
|
||||
t.Errorf("SavePresets failed: %v", err)
|
||||
}
|
||||
|
||||
loadedPresets, err := ds.GetPresets(account)
|
||||
loadedPresets, err := ds.GetPresets(account, device)
|
||||
if err != nil {
|
||||
t.Errorf("GetPresets failed: %v", err)
|
||||
}
|
||||
@@ -72,12 +72,12 @@ func TestDataStore(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = ds.SaveRecents(account, recents)
|
||||
err = ds.SaveRecents(account, device, recents)
|
||||
if err != nil {
|
||||
t.Errorf("SaveRecents failed: %v", err)
|
||||
}
|
||||
|
||||
loadedRecents, err := ds.GetRecents(account)
|
||||
loadedRecents, err := ds.GetRecents(account, device)
|
||||
if err != nil {
|
||||
t.Errorf("GetRecents failed: %v", err)
|
||||
}
|
||||
@@ -294,29 +294,37 @@ func TestConfiguredSources(t *testing.T) {
|
||||
|
||||
sources := []models.ConfiguredSource{
|
||||
{
|
||||
DisplayName: "Source 1",
|
||||
ID: "101",
|
||||
Secret: "secret1",
|
||||
SecretType: "type1",
|
||||
DisplayName: "Source 1",
|
||||
ID: "101",
|
||||
Secret: "secret1",
|
||||
SecretType: "type1",
|
||||
SourceKey: struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Account string `xml:"account,attr"`
|
||||
}{Type: "TUNEIN", Account: "user1"},
|
||||
SourceKeyType: "TUNEIN",
|
||||
SourceKeyAccount: "user1",
|
||||
},
|
||||
{
|
||||
DisplayName: "Source 2",
|
||||
ID: "102",
|
||||
Secret: "secret2",
|
||||
SecretType: "type2",
|
||||
DisplayName: "Source 2",
|
||||
ID: "102",
|
||||
Secret: "secret2",
|
||||
SecretType: "type2",
|
||||
SourceKey: struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Account string `xml:"account,attr"`
|
||||
}{Type: "PANDORA", Account: "user2"},
|
||||
SourceKeyType: "PANDORA",
|
||||
SourceKeyAccount: "user2",
|
||||
},
|
||||
}
|
||||
|
||||
err := ds.SaveConfiguredSources(account, sources)
|
||||
err := ds.SaveConfiguredSources(account, "any", sources)
|
||||
if err != nil {
|
||||
t.Fatalf("SaveConfiguredSources failed: %v", err)
|
||||
}
|
||||
|
||||
loadedSources, err := ds.GetConfiguredSources(account)
|
||||
loadedSources, err := ds.GetConfiguredSources(account, "any")
|
||||
if err != nil {
|
||||
t.Fatalf("GetConfiguredSources failed: %v", err)
|
||||
}
|
||||
@@ -343,12 +351,12 @@ func TestConfiguredSources(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = ds.SaveConfiguredSources(account, sources2)
|
||||
err = ds.SaveConfiguredSources(account, "any", sources2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
loadedSources2, err := ds.GetConfiguredSources(account)
|
||||
loadedSources2, err := ds.GetConfiguredSources(account, "any")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -23,17 +23,19 @@ func TestMargeETags(t *testing.T) {
|
||||
ds := datastore.NewDataStore(tempDir)
|
||||
|
||||
account := "12345"
|
||||
deviceID := "DEV1"
|
||||
accountDir := filepath.Join(tempDir, account)
|
||||
_ = os.MkdirAll(accountDir, 0755)
|
||||
deviceDir := filepath.Join(accountDir, "devices", deviceID)
|
||||
_ = os.MkdirAll(deviceDir, 0755)
|
||||
|
||||
// Create some initial data
|
||||
presetsFile := filepath.Join(accountDir, "Presets.xml")
|
||||
presetsFile := filepath.Join(deviceDir, "Presets.xml")
|
||||
_ = os.WriteFile(presetsFile, []byte("<presets/>"), 0644)
|
||||
|
||||
sourcesFile := filepath.Join(accountDir, "Sources.xml")
|
||||
sourcesFile := filepath.Join(deviceDir, "Sources.xml")
|
||||
_ = os.WriteFile(sourcesFile, []byte("<sources/>"), 0644)
|
||||
|
||||
recentsFile := filepath.Join(accountDir, "Recents.xml")
|
||||
recentsFile := filepath.Join(deviceDir, "Recents.xml")
|
||||
_ = os.WriteFile(recentsFile, []byte("<recents/>"), 0644)
|
||||
|
||||
// Ensure devices directory exists for AccountFull
|
||||
|
||||
@@ -36,7 +36,9 @@ func (s *Server) HandleMargeSourceProviders(w http.ResponseWriter, r *http.Reque
|
||||
func (s *Server) HandleMargeAccountFull(w http.ResponseWriter, r *http.Request) {
|
||||
account := chi.URLParam(r, "account")
|
||||
|
||||
etag := strconv.FormatInt(s.ds.GetETagForAccount(account), 10)
|
||||
device := r.URL.Query().Get("device")
|
||||
|
||||
etag := strconv.FormatInt(s.ds.GetETagForAccount(account, device), 10)
|
||||
if r.Header.Get("If-None-Match") == etag {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
@@ -79,14 +81,15 @@ func (s *Server) HandleMargeSoftwareUpdate(w http.ResponseWriter, r *http.Reques
|
||||
// HandleMargePresets returns the Marge presets for a device.
|
||||
func (s *Server) HandleMargePresets(w http.ResponseWriter, r *http.Request) {
|
||||
account := chi.URLParam(r, "account")
|
||||
device := chi.URLParam(r, "device")
|
||||
|
||||
etag := strconv.FormatInt(s.ds.GetETagForPresets(account), 10)
|
||||
etag := strconv.FormatInt(s.ds.GetETagForPresets(account, device), 10)
|
||||
if r.Header.Get("If-None-Match") == etag {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := marge.PresetsToXML(s.ds, account)
|
||||
data, err := marge.PresetsToXML(s.ds, account, device)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -102,7 +105,7 @@ func (s *Server) HandleMargeUpdatePreset(w http.ResponseWriter, r *http.Request)
|
||||
account := chi.URLParam(r, "account")
|
||||
device := chi.URLParam(r, "device")
|
||||
|
||||
etag := strconv.FormatInt(s.ds.GetETagForPresets(account), 10)
|
||||
etag := strconv.FormatInt(s.ds.GetETagForPresets(account, device), 10)
|
||||
w.Header()["ETag"] = []string{etag}
|
||||
|
||||
presetNumberStr := chi.URLParam(r, "presetNumber")
|
||||
@@ -134,7 +137,7 @@ func (s *Server) HandleMargeAddRecent(w http.ResponseWriter, r *http.Request) {
|
||||
account := chi.URLParam(r, "account")
|
||||
device := chi.URLParam(r, "device")
|
||||
|
||||
etag := strconv.FormatInt(s.ds.GetETagForRecents(account), 10)
|
||||
etag := strconv.FormatInt(s.ds.GetETagForRecents(account, device), 10)
|
||||
w.Header()["ETag"] = []string{etag}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
|
||||
@@ -135,12 +135,14 @@ func TestMargePresets(t *testing.T) {
|
||||
ds := datastore.NewDataStore(tempDir)
|
||||
|
||||
account := "12345"
|
||||
deviceID := "any"
|
||||
|
||||
accountDir := filepath.Join(tempDir, account)
|
||||
err = os.MkdirAll(accountDir, 0755)
|
||||
deviceDir := filepath.Join(accountDir, "devices", deviceID)
|
||||
err = os.MkdirAll(deviceDir, 0755)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create account dir: %v", err)
|
||||
t.Fatalf("Failed to create device dir: %v", err)
|
||||
}
|
||||
|
||||
r, _ := setupRouter("http://localhost:8001", ds)
|
||||
@@ -149,24 +151,17 @@ func TestMargePresets(t *testing.T) {
|
||||
defer ts.Close()
|
||||
|
||||
// Mock Sources.xml and Presets.xml
|
||||
if err := os.WriteFile(filepath.Join(accountDir, "Sources.xml"), []byte(`
|
||||
if err := os.WriteFile(filepath.Join(deviceDir, "Sources.xml"), []byte(`
|
||||
<sources>
|
||||
<source id="123" type="Audio">
|
||||
<createdOn>2012-09-19T12:43:00.000+00:00</createdOn>
|
||||
<credential type="token"></credential>
|
||||
<name>TUNEIN</name>
|
||||
<sourceproviderid>1</sourceproviderid>
|
||||
<sourcename>TUNEIN</sourcename>
|
||||
<sourcesettings></sourcesettings>
|
||||
<updatedOn>2012-09-19T12:43:00.000+00:00</updatedOn>
|
||||
<username></username>
|
||||
<source id="123" displayName="TUNEIN" secret="" secretType="Audio">
|
||||
<sourceKey type="TUNEIN" account=""/>
|
||||
</source>
|
||||
</sources>
|
||||
`), 0644); err != nil {
|
||||
t.Fatalf("Failed to write Sources.xml: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(accountDir, "Presets.xml"), []byte(`
|
||||
if err := os.WriteFile(filepath.Join(deviceDir, "Presets.xml"), []byte(`
|
||||
<presets>
|
||||
<preset id="1">
|
||||
<ContentItem source="TUNEIN" type="station" location="/station/s123" sourceAccount="" isPresetable="true">
|
||||
@@ -211,26 +206,28 @@ func TestMargeUpdatePreset(t *testing.T) {
|
||||
ds := datastore.NewDataStore(tempDir)
|
||||
|
||||
account := "12345"
|
||||
deviceID := "DEV1"
|
||||
|
||||
accountDir := filepath.Join(tempDir, account)
|
||||
err = os.MkdirAll(accountDir, 0755)
|
||||
deviceDir := filepath.Join(accountDir, "devices", deviceID)
|
||||
err = os.MkdirAll(deviceDir, 0755)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create account dir: %v", err)
|
||||
t.Fatalf("Failed to create device dir: %v", err)
|
||||
}
|
||||
|
||||
// Mock Sources.xml
|
||||
if err := os.WriteFile(filepath.Join(accountDir, "Sources.xml"), []byte(`
|
||||
if err := os.WriteFile(filepath.Join(deviceDir, "Sources.xml"), []byte(`
|
||||
<sources>
|
||||
<source id="SRC1" type="Audio">
|
||||
<sourcename>TUNEIN</sourcename>
|
||||
<source id="SRC1" displayName="TUNEIN" secret="" secretType="Audio">
|
||||
<sourceKey type="TUNEIN" account=""/>
|
||||
</source>
|
||||
</sources>
|
||||
`), 0644); err != nil {
|
||||
t.Fatalf("Failed to write Sources.xml: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(accountDir, "Presets.xml"), []byte(`<presets></presets>`), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(deviceDir, "Presets.xml"), []byte(`<presets></presets>`), 0644); err != nil {
|
||||
t.Fatalf("Failed to write Presets.xml: %v", err)
|
||||
}
|
||||
|
||||
@@ -248,7 +245,7 @@ func TestMargeUpdatePreset(t *testing.T) {
|
||||
<containerArt>http://example.com/new.jpg</containerArt>
|
||||
</preset>`
|
||||
|
||||
res, err := http.Post(ts.URL+"/marge/accounts/"+account+"/devices/DEV1/presets/1", "application/xml", strings.NewReader(payload))
|
||||
res, err := http.Post(ts.URL+"/marge/accounts/"+account+"/devices/"+deviceID+"/presets/1", "application/xml", strings.NewReader(payload))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -261,7 +258,7 @@ func TestMargeUpdatePreset(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify file was saved
|
||||
presetData, _ := os.ReadFile(filepath.Join(accountDir, "Presets.xml"))
|
||||
presetData, _ := os.ReadFile(filepath.Join(deviceDir, "Presets.xml"))
|
||||
if !strings.Contains(string(presetData), "New Preset") {
|
||||
t.Error("Preset was not saved to datastore")
|
||||
}
|
||||
@@ -278,26 +275,28 @@ func TestMargeDeviceInfo(t *testing.T) {
|
||||
ds := datastore.NewDataStore(tempDir)
|
||||
|
||||
account := "12345"
|
||||
deviceID := "DEV1"
|
||||
|
||||
accountDir := filepath.Join(tempDir, account)
|
||||
err = os.MkdirAll(accountDir, 0755)
|
||||
deviceDir := filepath.Join(accountDir, "devices", deviceID)
|
||||
err = os.MkdirAll(deviceDir, 0755)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create account dir: %v", err)
|
||||
t.Fatalf("Failed to create device dir: %v", err)
|
||||
}
|
||||
|
||||
// Mock Sources.xml
|
||||
if err := os.WriteFile(filepath.Join(accountDir, "Sources.xml"), []byte(`
|
||||
if err := os.WriteFile(filepath.Join(deviceDir, "Sources.xml"), []byte(`
|
||||
<sources>
|
||||
<source id="SRC1" type="Audio">
|
||||
<sourcename>TUNEIN</sourcename>
|
||||
<source id="SRC1" displayName="TUNEIN" secret="" secretType="Audio">
|
||||
<sourceKey type="TUNEIN" account=""/>
|
||||
</source>
|
||||
</sources>
|
||||
`), 0644); err != nil {
|
||||
t.Fatalf("Failed to write Sources.xml: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(accountDir, "Recents.xml"), []byte(`<recents></recents>`), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(deviceDir, "Recents.xml"), []byte(`<recents></recents>`), 0644); err != nil {
|
||||
t.Fatalf("Failed to write Recents.xml: %v", err)
|
||||
}
|
||||
|
||||
@@ -314,7 +313,7 @@ func TestMargeDeviceInfo(t *testing.T) {
|
||||
<contentItemType>station</contentItemType>
|
||||
</recent>`
|
||||
|
||||
res, err := http.Post(ts.URL+"/marge/accounts/"+account+"/devices/DEV1/recents", "application/xml", strings.NewReader(payload))
|
||||
res, err := http.Post(ts.URL+"/marge/accounts/"+account+"/devices/"+deviceID+"/recents", "application/xml", strings.NewReader(payload))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -326,7 +325,7 @@ func TestMargeDeviceInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify file was saved
|
||||
recentData, _ := os.ReadFile(filepath.Join(accountDir, "Recents.xml"))
|
||||
recentData, _ := os.ReadFile(filepath.Join(deviceDir, "Recents.xml"))
|
||||
if !strings.Contains(string(recentData), "Recent Station") {
|
||||
t.Error("Recent was not saved to datastore")
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gesellix/bose-soundtouch/pkg/models"
|
||||
"github.com/gesellix/bose-soundtouch/pkg/service/setup"
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -25,9 +27,53 @@ func (s *Server) HandleListDiscoveredDevices(w http.ResponseWriter, _ *http.Requ
|
||||
}
|
||||
}
|
||||
|
||||
// HandleAddManualDevice adds a device manually by IP.
|
||||
func (s *Server) HandleAddManualDevice(w http.ResponseWriter, r *http.Request) {
|
||||
var body struct {
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if body.IP == "" {
|
||||
http.Error(w, "IP address is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Try to get live info
|
||||
liveInfo, err := s.sm.GetLiveDeviceInfo(body.IP)
|
||||
if err != nil {
|
||||
// Even if we can't get live info, we might want to add it?
|
||||
// But usually we need at least the serial for proper account management.
|
||||
http.Error(w, "Failed to reach device at "+body.IP+": "+err.Error(), http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
|
||||
// Reuse handleDiscoveredDevice logic via a fake models.DiscoveredDevice
|
||||
d := models.DiscoveredDevice{
|
||||
Name: liveInfo.Name,
|
||||
Host: body.IP,
|
||||
ModelID: liveInfo.Type,
|
||||
SerialNo: liveInfo.SerialNumber,
|
||||
DiscoveryMethod: "manual",
|
||||
}
|
||||
|
||||
s.handleDiscoveredDevice(d)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
if err := json.NewEncoder(w).Encode(map[string]bool{"ok": true}); err != nil {
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// HandleTriggerDiscovery triggers a new device discovery scan.
|
||||
func (s *Server) HandleTriggerDiscovery(w http.ResponseWriter, r *http.Request) {
|
||||
go s.DiscoverDevices(r.Context())
|
||||
func (s *Server) HandleTriggerDiscovery(w http.ResponseWriter, _ *http.Request) {
|
||||
//nolint:contextcheck
|
||||
go s.DiscoverDevices(context.Background())
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
_, _ = w.Write([]byte(`{"status": "Discovery started"}`))
|
||||
@@ -388,6 +434,23 @@ func (s *Server) HandleTestHostsRedirection(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
}
|
||||
|
||||
// HandleInitialSync fetches presets, recents and sources from the device and saves them to the datastore.
|
||||
func (s *Server) HandleInitialSync(w http.ResponseWriter, r *http.Request) {
|
||||
deviceIP := chi.URLParam(r, "deviceIP")
|
||||
if deviceIP == "" {
|
||||
http.Error(w, "Missing deviceIP", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.sm.SyncDeviceData(deviceIP); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(`{"ok": true}`))
|
||||
}
|
||||
|
||||
// HandleTestConnection performs a connection check from the device to the server.
|
||||
func (s *Server) HandleTestConnection(w http.ResponseWriter, r *http.Request) {
|
||||
deviceIP := chi.URLParam(r, "deviceIP")
|
||||
|
||||
@@ -44,16 +44,18 @@ func (s *Server) DiscoverDevices(ctx context.Context) {
|
||||
|
||||
log.Println("Scanning for Bose devices...")
|
||||
|
||||
// Use background context if none provided or if it's likely a request context
|
||||
if ctx == nil {
|
||||
var cancel context.CancelFunc
|
||||
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
// Always wrap in a timeout to prevent hanging forever
|
||||
discoveryCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
svc := discovery.NewService(10 * time.Second)
|
||||
|
||||
devices, err := svc.DiscoverDevices(ctx)
|
||||
devices, err := svc.DiscoverDevices(discoveryCtx)
|
||||
if err != nil {
|
||||
log.Printf("Discovery error: %v", err)
|
||||
return
|
||||
@@ -94,6 +96,7 @@ func (s *Server) handleDiscoveredDevice(d models.DiscoveredDevice) {
|
||||
DeviceSerialNumber: d.SerialNo,
|
||||
ProductCode: d.ModelID,
|
||||
FirmwareVersion: "0.0.0", // Unknown from discovery
|
||||
DiscoveryMethod: d.DiscoveryMethod,
|
||||
}
|
||||
|
||||
// If we had an IP-based entry and now have a Serial, clean up the IP-based entry
|
||||
@@ -109,7 +112,8 @@ func (s *Server) handleDiscoveredDevice(d models.DiscoveredDevice) {
|
||||
|
||||
func (s *Server) findExistingDeviceID(d models.DiscoveredDevice) string {
|
||||
allDevices, _ := s.ds.ListAllDevices()
|
||||
for _, known := range allDevices {
|
||||
for i := range allDevices {
|
||||
known := allDevices[i]
|
||||
if d.SerialNo != "" && (known.DeviceID == d.SerialNo || known.DeviceSerialNumber == d.SerialNo) {
|
||||
if known.DeviceID != "" {
|
||||
return known.DeviceID
|
||||
|
||||
@@ -9,3 +9,28 @@ pre { background-color: #eee; padding: 10px; overflow-x: auto; font-size: 12px;
|
||||
.diff-container { display: flex; gap: 10px; }
|
||||
.diff-pane { flex: 1; min-width: 0; }
|
||||
.config-header { font-weight: bold; margin-bottom: 5px; display: block; }
|
||||
|
||||
/* Tabs */
|
||||
.tabs { margin-top: 20px; }
|
||||
.tab-buttons { display: flex; border-bottom: 1px solid #ddd; margin-bottom: 20px; }
|
||||
.tab-btn { background: #f8f8f8; border: 1px solid #ddd; border-bottom: none; padding: 10px 20px; margin-right: 5px; border-top-left-radius: 4px; border-top-right-radius: 4px; }
|
||||
.tab-btn:hover { background: #eee; }
|
||||
.tab-btn.active { background: white; border-bottom: 2px solid #2196F3; font-weight: bold; }
|
||||
.tab-content { display: none; padding: 10px; }
|
||||
.tab-content.active { display: block; }
|
||||
|
||||
.device-selection {
|
||||
margin-bottom: 20px;
|
||||
padding: 10px;
|
||||
background-color: #f0f7ff;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #d0e0f0;
|
||||
}
|
||||
.device-selection label {
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.device-selection select {
|
||||
padding: 5px;
|
||||
min-width: 250px;
|
||||
}
|
||||
|
||||
+173
-129
@@ -8,149 +8,193 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Soundcork Management</h1>
|
||||
<h2>Discovered Devices <span id="discovery-indicator" style="font-size: 0.5em; vertical-align: middle; display: none;">🔍 Scanning...</span></h2>
|
||||
<div id="device-list">Loading devices...</div>
|
||||
|
||||
<div id="manual-entry" style="margin-top: 20px; border-top: 1px solid #eee; padding-top: 10px;">
|
||||
<h3>Manual Entry</h3>
|
||||
<input type="text" id="manual-ip" placeholder="Device IP (e.g. 192.168.1.100)">
|
||||
<button onclick="showSummary(document.getElementById('manual-ip').value)">Check Migration</button>
|
||||
|
||||
<h3 style="margin-top: 20px;">Settings</h3>
|
||||
<div style="margin-bottom: 10px;">
|
||||
<label for="target-domain">Target Domain:</label>
|
||||
<input type="text" id="target-domain" placeholder="http://localhost:8000" style="width: 300px;">
|
||||
<span style="font-size: 0.8em; color: #666;">(This URL will be used for standard services)</span>
|
||||
<div class="tabs">
|
||||
<div class="tab-buttons">
|
||||
<button class="tab-btn active" onclick="openTab(event, 'tab-devices')">1. Devices</button>
|
||||
<button class="tab-btn" onclick="openTab(event, 'tab-sync')">2. Data Sync</button>
|
||||
<button class="tab-btn" onclick="openTab(event, 'tab-migration')">3. Migration</button>
|
||||
<button class="tab-btn" onclick="openTab(event, 'tab-settings')">4. Settings</button>
|
||||
</div>
|
||||
<div style="margin-bottom: 10px;">
|
||||
<label for="proxy-domain">Proxy Domain:</label>
|
||||
<input type="text" id="proxy-domain" placeholder="http://localhost:8000" style="width: 300px;">
|
||||
<span style="font-size: 0.8em; color: #666;">(This URL will be used to proxy upstream Bose services)</span>
|
||||
</div>
|
||||
<div style="margin-bottom: 10px;">
|
||||
Proxy Logging:
|
||||
<label><input type="checkbox" id="proxy-redact" onchange="updateProxySettings()"> Redact Sensitive Headers</label>
|
||||
<label style="margin-left: 15px;"><input type="checkbox" id="proxy-log-body" onchange="updateProxySettings()"> Log Bodies</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="status" class="status"></div>
|
||||
|
||||
<div id="migration-summary" class="summary-box">
|
||||
<h3>Migration Summary for <span id="summary-ip"></span></h3>
|
||||
<p>SSH Connection: <span id="ssh-status"></span></p>
|
||||
<p id="original-config-status" style="display: none;">Backup: ✅ Found .original config at <code>/opt/Bose/etc/SoundTouchSdkPrivateCfg.xml.original</code> <button onclick="toggleOriginalConfig()">Show Original Config</button></p>
|
||||
<p id="no-original-config-status" style="display: none;">Backup: ❌ Not found <button id="backup-config-btn">Backup Config Now</button></p>
|
||||
<p>Remote Services Enabled: <span id="remote-services-status"></span> <span id="remote-services-found" style="font-size: 0.8em; color: #666;"></span></p>
|
||||
<p>Local Root CA Trusted: <span id="ca-trust-status"></span> <button id="trust-ca-btn" style="display: none; background-color: #607D8B; color: white; border: none; padding: 2px 8px; font-size: 0.8em; margin-left: 10px;">Trust CA Now</button></p>
|
||||
|
||||
<div id="connection-test" style="margin: 15px 0; padding: 10px; border: 1px solid #ddd; background-color: #eefbff;">
|
||||
<strong>HTTPS Connection Test:</strong><br>
|
||||
<span style="font-size: 0.85em; color: #555;">Verify the device can reach the server over HTTPS.</span>
|
||||
<div style="margin-top: 10px;">
|
||||
URL: <code id="test-url"></code>
|
||||
<!-- Tab 1: Devices -->
|
||||
<div id="tab-devices" class="tab-content active">
|
||||
<h2>Known Devices <span id="discovery-indicator" style="font-size: 0.5em; vertical-align: middle; display: none;">🔍 Scanning...</span></h2>
|
||||
<div id="device-list">Loading devices...</div>
|
||||
<div style="margin-top: 20px;">
|
||||
<button onclick="triggerDiscovery()">Scan Again</button>
|
||||
<input type="text" id="add-manual-ip" placeholder="Manual IP (e.g. 192.168.1.100)" style="margin-left: 20px; padding: 4px;">
|
||||
<button onclick="addManualDevice()">Add Device</button>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<button id="test-connection-explicit-btn" style="background-color: #607D8B; color: white; border: none; padding: 5px 10px; font-size: 0.9em;">Test with Explicit CA.crt</button>
|
||||
<button id="test-connection-trusted-btn" style="background-color: #607D8B; color: white; border: none; padding: 5px 10px; font-size: 0.9em;">Test with Shared Trust Store</button>
|
||||
</div>
|
||||
<div id="test-result" style="margin-top: 10px; display: none; padding: 10px; border-radius: 4px; font-family: monospace; white-space: pre-wrap; font-size: 0.85em; max-height: 200px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
|
||||
<div id="hosts-redirection-test" style="margin: 15px 0; padding: 10px; border: 1px solid #ddd; background-color: #fff4e6; display: none;">
|
||||
<strong>Preliminary /etc/hosts Test:</strong><br>
|
||||
<span style="font-size: 0.85em; color: #555;">Verify the device's /etc/hosts mechanism before full migration.</span>
|
||||
<div style="margin-top: 10px;">
|
||||
Domain: <code>custom-test-api.bose.fake</code>
|
||||
<!-- Tab 2: Data Sync -->
|
||||
<div id="tab-sync" class="tab-content">
|
||||
<h2>Initial Data Sync</h2>
|
||||
<p>Before migrating, fetch your presets, recents, and configured sources from the device to ensure they are available locally.</p>
|
||||
<div class="device-selection">
|
||||
<label for="sync-device-list">Device:</label>
|
||||
<select id="sync-device-list">
|
||||
<option value="">-- Select a device --</option>
|
||||
</select>
|
||||
<button id="sync-now-btn">Start Sync</button>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<button id="test-hosts-btn" style="background-color: #FF9800; color: white; border: none; padding: 5px 10px; font-size: 0.9em;">Test Hosts Redirection</button>
|
||||
<div id="sync-status" class="status"></div>
|
||||
<div id="sync-results" style="margin-top: 20px; display: none;">
|
||||
<h3>Sync Results</h3>
|
||||
<div id="sync-log" style="font-family: monospace; background: #f4f4f4; padding: 10px; border-radius: 4px; max-height: 300px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
<div id="hosts-test-result" style="margin-top: 10px; display: none; padding: 10px; border-radius: 4px; font-family: monospace; white-space: pre-wrap; font-size: 0.85em; max-height: 200px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
|
||||
<div style="margin: 15px 0; padding: 10px; border: 1px solid #ddd; background-color: #f9f9f9;">
|
||||
<label for="migration-method"><strong>Migration Method:</strong></label>
|
||||
<select id="migration-method" onchange="toggleMigrationMethod()">
|
||||
<option value="xml">XML Configuration (Recommended - redirects specific services)</option>
|
||||
<option value="hosts">/etc/hosts + Root CA (Advanced - global redirection)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="original-config-pane" style="display: none; margin-bottom: 20px;">
|
||||
<span class="config-header">Original Config (Backup)</span>
|
||||
<pre id="original-config-content"></pre>
|
||||
</div>
|
||||
|
||||
<div id="service-options" style="margin-bottom: 20px; display: none;">
|
||||
<h4>Service Implementations</h4>
|
||||
<table>
|
||||
<tr><th>Service</th><th>Original URL</th><th>Implementation</th></tr>
|
||||
<tr>
|
||||
<td>Marge (Streaming)</td>
|
||||
<td id="orig-marge">loading...</td>
|
||||
<td>
|
||||
<select id="opt-marge" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Stats</td>
|
||||
<td id="orig-stats">loading...</td>
|
||||
<td>
|
||||
<select id="opt-stats" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Software Update</td>
|
||||
<td id="orig-sw_update">loading...</td>
|
||||
<td>
|
||||
<select id="opt-sw_update" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>BMX (Registry)</td>
|
||||
<td id="orig-bmx">loading...</td>
|
||||
<td>
|
||||
<select id="opt-bmx" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="diff-container">
|
||||
<div id="xml-diff-pane" class="diff-pane">
|
||||
<span class="config-header">Current Config (on Speaker)</span>
|
||||
<pre id="current-config"></pre>
|
||||
<!-- Tab 3: Migration -->
|
||||
<div id="tab-migration" class="tab-content">
|
||||
<h2>Device Migration</h2>
|
||||
<div class="device-selection">
|
||||
<label for="migration-device-list">Device:</label>
|
||||
<select id="migration-device-list" onchange="showSummary(this.value)">
|
||||
<option value="">-- Select a device --</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="planned-xml-pane" class="diff-pane">
|
||||
<span class="config-header">Planned Config (Soundcork)</span>
|
||||
<pre id="planned-config"></pre>
|
||||
</div>
|
||||
<div id="planned-hosts-pane" class="diff-pane" style="display: none;">
|
||||
<span class="config-header">Planned /etc/hosts Entries</span>
|
||||
<pre id="planned-hosts"></pre>
|
||||
<div style="margin-top: 10px; font-size: 0.9em; color: #666;">
|
||||
<strong>Note:</strong> This method also injects the local Root CA into <code>/etc/pki/tls/certs/ca-bundle.crt</code> to enable secure HTTPS communication.
|
||||
|
||||
<div id="status" class="status"></div>
|
||||
|
||||
<div id="migration-summary" class="summary-box" style="display: none;">
|
||||
<h3>Migration Summary for <span id="summary-ip"></span></h3>
|
||||
<p>SSH Connection: <span id="ssh-status"></span></p>
|
||||
<p id="original-config-status" style="display: none;">Backup: ✅ Found .original config at <code>/opt/Bose/etc/SoundTouchSdkPrivateCfg.xml.original</code> <button onclick="toggleOriginalConfig()">Show Original Config</button></p>
|
||||
<p id="no-original-config-status" style="display: none;">Backup: ❌ Not found <button id="backup-config-btn">Backup Config Now</button></p>
|
||||
<p>Remote Services Enabled: <span id="remote-services-status"></span> <span id="remote-services-found" style="font-size: 0.8em; color: #666;"></span></p>
|
||||
<p>Local Root CA Trusted: <span id="ca-trust-status"></span> <button id="trust-ca-btn" style="display: none; background-color: #607D8B; color: white; border: none; padding: 2px 8px; font-size: 0.8em; margin-left: 10px;">Trust CA Now</button></p>
|
||||
|
||||
<div id="connection-test" style="margin: 15px 0; padding: 10px; border: 1px solid #ddd; background-color: #eefbff;">
|
||||
<strong>HTTPS Connection Test:</strong><br>
|
||||
<span style="font-size: 0.85em; color: #555;">Verify the device can reach the server over HTTPS.</span>
|
||||
<div style="margin-top: 10px;">
|
||||
URL: <code id="test-url"></code>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<button id="test-connection-explicit-btn" style="background-color: #607D8B; color: white; border: none; padding: 5px 10px; font-size: 0.9em;">Test with Explicit CA.crt</button>
|
||||
<button id="test-connection-trusted-btn" style="background-color: #607D8B; color: white; border: none; padding: 5px 10px; font-size: 0.9em;">Test with Shared Trust Store</button>
|
||||
</div>
|
||||
<div id="test-result" style="margin-top: 10px; display: none; padding: 10px; border-radius: 4px; font-family: monospace; white-space: pre-wrap; font-size: 0.85em; max-height: 200px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
|
||||
<div id="hosts-redirection-test" style="margin: 15px 0; padding: 10px; border: 1px solid #ddd; background-color: #fff4e6; display: none;">
|
||||
<strong>Preliminary /etc/hosts Test:</strong><br>
|
||||
<span style="font-size: 0.85em; color: #555;">Verify the device's /etc/hosts mechanism before full migration.</span>
|
||||
<div style="margin-top: 10px;">
|
||||
Domain: <code>custom-test-api.bose.fake</code>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<button id="test-hosts-btn" style="background-color: #FF9800; color: white; border: none; padding: 5px 10px; font-size: 0.9em;">Test Hosts Redirection</button>
|
||||
</div>
|
||||
<div id="hosts-test-result" style="margin-top: 10px; display: none; padding: 10px; border-radius: 4px; font-family: monospace; white-space: pre-wrap; font-size: 0.85em; max-height: 200px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
|
||||
<div style="margin: 15px 0; padding: 10px; border: 1px solid #ddd; background-color: #f9f9f9;">
|
||||
<label for="migration-method"><strong>Migration Method:</strong></label>
|
||||
<select id="migration-method" onchange="toggleMigrationMethod()">
|
||||
<option value="xml">XML Configuration (Recommended - redirects specific services)</option>
|
||||
<option value="hosts">/etc/hosts + Root CA (Advanced - global redirection)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="original-config-pane" style="display: none; margin-bottom: 20px;">
|
||||
<span class="config-header">Original Config (Backup)</span>
|
||||
<pre id="original-config-content"></pre>
|
||||
</div>
|
||||
|
||||
<div id="service-options" style="margin-bottom: 20px; display: none;">
|
||||
<h4>Service Implementations</h4>
|
||||
<table>
|
||||
<tr><th>Service</th><th>Original URL</th><th>Implementation</th></tr>
|
||||
<tr>
|
||||
<td>Marge (Streaming)</td>
|
||||
<td id="orig-marge">loading...</td>
|
||||
<td>
|
||||
<select id="opt-marge" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Stats</td>
|
||||
<td id="orig-stats">loading...</td>
|
||||
<td>
|
||||
<select id="opt-stats" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Software Update</td>
|
||||
<td id="orig-sw_update">loading...</td>
|
||||
<td>
|
||||
<select id="opt-sw_update" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>BMX (Registry)</td>
|
||||
<td id="orig-bmx">loading...</td>
|
||||
<td>
|
||||
<select id="opt-bmx" onchange="refreshSummary()">
|
||||
<option value="soundcork">Soundcork (Go/Python)</option>
|
||||
<option value="original">Original (Proxy via soundcork-go)</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="diff-container">
|
||||
<div id="xml-diff-pane" class="diff-pane">
|
||||
<span class="config-header">Current Config (on Speaker)</span>
|
||||
<pre id="current-config"></pre>
|
||||
</div>
|
||||
<div id="planned-xml-pane" class="diff-pane">
|
||||
<span class="config-header">Planned Config (Soundcork)</span>
|
||||
<pre id="planned-config"></pre>
|
||||
</div>
|
||||
<div id="planned-hosts-pane" class="diff-pane" style="display: none;">
|
||||
<span class="config-header">Planned /etc/hosts Entries</span>
|
||||
<pre id="planned-hosts"></pre>
|
||||
<div style="margin-top: 10px; font-size: 0.9em; color: #666;">
|
||||
<strong>Note:</strong> This method also injects the local Root CA into <code>/etc/pki/tls/certs/ca-bundle.crt</code> to enable secure HTTPS communication.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top: 15px;">
|
||||
<button id="confirm-migrate-btn" style="background-color: #4CAF50; color: white; border: none; padding: 10px 20px;">Confirm Migration & Reboot</button>
|
||||
<button id="ensure-remote-btn" style="background-color: #2196F3; color: white; border: none; padding: 10px 20px;">Enable Persistent Remote Services</button>
|
||||
<button id="remove-remote-btn" style="background-color: #f44336; color: white; border: none; padding: 10px 20px;">Remove Persistent Remote Services</button>
|
||||
<button onclick="document.getElementById('migration-summary').style.display='none'" style="padding: 10px 20px;">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top: 15px;">
|
||||
<button id="confirm-migrate-btn" style="background-color: #4CAF50; color: white; border: none; padding: 10px 20px;">Confirm Migration & Reboot</button>
|
||||
<button id="ensure-remote-btn" style="background-color: #2196F3; color: white; border: none; padding: 10px 20px;">Enable Persistent Remote Services</button>
|
||||
<button id="remove-remote-btn" style="background-color: #f44336; color: white; border: none; padding: 10px 20px;">Remove Persistent Remote Services</button>
|
||||
<button onclick="document.getElementById('migration-summary').style.display='none'" style="padding: 10px 20px;">Cancel</button>
|
||||
|
||||
<!-- Tab 4: Settings -->
|
||||
<div id="tab-settings" class="tab-content">
|
||||
<h2>System Settings</h2>
|
||||
<div style="margin-bottom: 20px;">
|
||||
<label for="target-domain">Target Domain:</label>
|
||||
<input type="text" id="target-domain" placeholder="http://localhost:8000" style="width: 300px;">
|
||||
<span style="font-size: 0.8em; color: #666;">(This URL will be used for standard services)</span>
|
||||
</div>
|
||||
<div style="margin-bottom: 20px;">
|
||||
<label for="proxy-domain">Proxy Domain:</label>
|
||||
<input type="text" id="proxy-domain" placeholder="http://localhost:8000" style="width: 300px;">
|
||||
<span style="font-size: 0.8em; color: #666;">(This URL will be used to proxy upstream Bose services)</span>
|
||||
</div>
|
||||
<div style="margin-bottom: 20px;">
|
||||
Proxy Logging:
|
||||
<label><input type="checkbox" id="proxy-redact" onchange="updateProxySettings()"> Redact Sensitive Headers</label>
|
||||
<label style="margin-left: 15px;"><input type="checkbox" id="proxy-log-body" onchange="updateProxySettings()"> Log Bodies</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -46,12 +46,22 @@ async function fetchDevices() {
|
||||
const response = await fetch('/setup/devices');
|
||||
const devices = await response.json();
|
||||
const container = document.getElementById('device-list');
|
||||
const syncSelector = document.getElementById('sync-device-list');
|
||||
const migrationSelector = document.getElementById('migration-device-list');
|
||||
|
||||
if (devices.length === 0) {
|
||||
container.innerHTML = 'No devices found.';
|
||||
container.innerHTML = 'No devices known yet.';
|
||||
} else {
|
||||
let html = '<table><tr><th>Name</th><th>IP Address</th><th>Model</th><th>Serial Number</th><th>Firmware</th><th>Action</th></tr>';
|
||||
let html = '<table><tr><th>Name</th><th>IP Address</th><th>Model</th><th>Serial Number</th><th>Firmware</th><th>Method</th><th>Action</th></tr>';
|
||||
|
||||
// Clear and repopulate selectors
|
||||
const currentSyncVal = syncSelector.value;
|
||||
const currentMigrationVal = migrationSelector.value;
|
||||
syncSelector.innerHTML = '<option value="">-- Select a device --</option>';
|
||||
migrationSelector.innerHTML = '<option value="">-- Select a device --</option>';
|
||||
|
||||
devices.forEach(d => {
|
||||
const methodLabel = d.discovery_method === 'manual' ? '👤 Manual' : '🔍 Auto';
|
||||
html += `
|
||||
<tr id="device-row-${d.ip_address.replace(/\./g, '-')}">
|
||||
<td class="col-name">${d.name}</td>
|
||||
@@ -59,13 +69,30 @@ async function fetchDevices() {
|
||||
<td class="col-model">${d.product_code}</td>
|
||||
<td class="col-serial">${d.device_serial_number}</td>
|
||||
<td class="col-firmware">${d.firmware_version || '0.0.0'}</td>
|
||||
<td><button onclick="showSummary('${d.ip_address}')">Prepare Migration</button></td>
|
||||
<td class="col-method">${methodLabel}</td>
|
||||
<td>
|
||||
<button onclick="prepareSync('${d.ip_address}')">Sync Data</button>
|
||||
<button onclick="prepareMigration('${d.ip_address}')">Migrate</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
const optSync = document.createElement('option');
|
||||
optSync.value = d.ip_address;
|
||||
optSync.textContent = `${d.name} (${d.ip_address})`;
|
||||
syncSelector.appendChild(optSync);
|
||||
|
||||
const optMigrate = document.createElement('option');
|
||||
optMigrate.value = d.ip_address;
|
||||
optMigrate.textContent = `${d.name} (${d.ip_address})`;
|
||||
migrationSelector.appendChild(optMigrate);
|
||||
});
|
||||
html += '</table>';
|
||||
container.innerHTML = html;
|
||||
|
||||
if (currentSyncVal) syncSelector.value = currentSyncVal;
|
||||
if (currentMigrationVal) migrationSelector.value = currentMigrationVal;
|
||||
|
||||
// Asynchronously fetch live info for each device
|
||||
devices.forEach(d => updateDeviceInfo(d.ip_address));
|
||||
}
|
||||
@@ -74,15 +101,125 @@ async function fetchDevices() {
|
||||
}
|
||||
}
|
||||
|
||||
function prepareSync(ip) {
|
||||
document.getElementById('sync-device-list').value = ip;
|
||||
openTab(null, 'tab-sync');
|
||||
}
|
||||
|
||||
function prepareMigration(ip) {
|
||||
document.getElementById('migration-device-list').value = ip;
|
||||
openTab(null, 'tab-migration');
|
||||
showSummary(ip);
|
||||
}
|
||||
|
||||
function openTab(evt, tabId) {
|
||||
const tabcontents = document.getElementsByClassName("tab-content");
|
||||
for (let i = 0; i < tabcontents.length; i++) {
|
||||
tabcontents[i].className = tabcontents[i].className.replace(" active", "");
|
||||
}
|
||||
|
||||
const tablinks = document.getElementsByClassName("tab-btn");
|
||||
for (let i = 0; i < tablinks.length; i++) {
|
||||
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
||||
}
|
||||
|
||||
const content = document.getElementById(tabId);
|
||||
if (content) {
|
||||
content.className += " active";
|
||||
}
|
||||
|
||||
if (evt) {
|
||||
evt.currentTarget.className += " active";
|
||||
} else {
|
||||
// Find the button that corresponds to the tabId and activate it
|
||||
for (let i = 0; i < tablinks.length; i++) {
|
||||
const onclick = tablinks[i].getAttribute('onclick');
|
||||
if (onclick && onclick.includes(tabId)) {
|
||||
tablinks[i].className += " active";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function startSync() {
|
||||
const ip = document.getElementById('sync-device-list').value;
|
||||
if (!ip) {
|
||||
alert('Please select a device first');
|
||||
return;
|
||||
}
|
||||
|
||||
const status = document.getElementById('sync-status');
|
||||
const results = document.getElementById('sync-results');
|
||||
const log = document.getElementById('sync-log');
|
||||
|
||||
status.style.display = 'block';
|
||||
status.style.backgroundColor = '#eef';
|
||||
status.textContent = 'Syncing data from ' + ip + '...';
|
||||
results.style.display = 'none';
|
||||
log.innerHTML = '';
|
||||
|
||||
try {
|
||||
const response = await fetch('/setup/sync/' + ip, { method: 'POST' });
|
||||
if (response.ok) {
|
||||
status.style.backgroundColor = '#dfd';
|
||||
status.textContent = '✅ Sync completed successfully!';
|
||||
results.style.display = 'block';
|
||||
log.innerHTML = 'Data fetched and saved to local datastore.\nPresets: OK\nRecents: OK\nSources: OK';
|
||||
} else {
|
||||
const err = await response.text();
|
||||
throw new Error(err);
|
||||
}
|
||||
} catch (error) {
|
||||
status.style.backgroundColor = '#fdd';
|
||||
status.textContent = '❌ Sync failed: ' + error.message;
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
fetchSettings();
|
||||
fetchDevices();
|
||||
triggerDiscovery();
|
||||
|
||||
document.getElementById('sync-now-btn').onclick = startSync;
|
||||
});
|
||||
|
||||
|
||||
async function addManualDevice() {
|
||||
const ip = document.getElementById('add-manual-ip').value.trim();
|
||||
if (!ip) {
|
||||
alert('Please enter an IP address');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/setup/devices', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ip: ip })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
document.getElementById('add-manual-ip').value = '';
|
||||
fetchDevices();
|
||||
} else {
|
||||
const err = await response.text();
|
||||
alert('Failed to add device: ' + err);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error adding device: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function triggerDiscovery() {
|
||||
const indicator = document.getElementById('discovery-indicator');
|
||||
indicator.style.display = 'inline';
|
||||
if (indicator) indicator.style.display = 'inline';
|
||||
try {
|
||||
await fetch('/setup/discover', { method: 'POST' });
|
||||
pollDiscoveryStatus();
|
||||
} catch (error) {
|
||||
console.error('Failed to trigger discovery', error);
|
||||
indicator.style.display = 'none';
|
||||
if (indicator) indicator.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,12 +231,12 @@ async function pollDiscoveryStatus() {
|
||||
if (data.discovering) {
|
||||
setTimeout(pollDiscoveryStatus, 2000);
|
||||
} else {
|
||||
indicator.style.display = 'none';
|
||||
if (indicator) indicator.style.display = 'none';
|
||||
fetchDevices();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check discovery status', error);
|
||||
indicator.style.display = 'none';
|
||||
if (indicator) indicator.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,10 +249,17 @@ async function updateDeviceInfo(ip) {
|
||||
const rowId = 'device-row-' + ip.replace(/\./g, '-');
|
||||
const row = document.getElementById(rowId);
|
||||
if (row) {
|
||||
if (info.name) row.querySelector('.col-name').innerText = info.name;
|
||||
if (info.type) row.querySelector('.col-model').innerText = info.type;
|
||||
if (info.serialNumber) row.querySelector('.col-serial').innerText = info.serialNumber;
|
||||
if (info.softwareVersion) row.querySelector('.col-firmware').innerText = info.softwareVersion;
|
||||
const nameEl = row.querySelector('.col-name');
|
||||
if (nameEl && info.name) nameEl.innerText = info.name;
|
||||
|
||||
const modelEl = row.querySelector('.col-model');
|
||||
if (modelEl && info.type) modelEl.innerText = info.type;
|
||||
|
||||
const serialEl = row.querySelector('.col-serial');
|
||||
if (serialEl && info.serialNumber) serialEl.innerText = info.serialNumber;
|
||||
|
||||
const firmwareEl = row.querySelector('.col-firmware');
|
||||
if (firmwareEl && info.softwareVersion) firmwareEl.innerText = info.softwareVersion;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to fetch live info for ' + ip, error);
|
||||
@@ -124,7 +268,7 @@ async function updateDeviceInfo(ip) {
|
||||
|
||||
async function showSummary(ip) {
|
||||
if (!ip) {
|
||||
alert('Please enter a valid IP address.');
|
||||
document.getElementById('migration-summary').style.display = 'none';
|
||||
return;
|
||||
}
|
||||
const targetUrl = document.getElementById('target-domain').value;
|
||||
@@ -162,10 +306,17 @@ async function showSummary(ip) {
|
||||
const rowId = 'device-row-' + ip.replace(/\./g, '-');
|
||||
const row = document.getElementById(rowId);
|
||||
if (row) {
|
||||
if (summary.device_name) row.querySelector('.col-name').innerText = summary.device_name;
|
||||
if (summary.device_model) row.querySelector('.col-model').innerText = summary.device_model;
|
||||
if (summary.device_serial) row.querySelector('.col-serial').innerText = summary.device_serial;
|
||||
if (summary.firmware_version) row.querySelector('.col-firmware').innerText = summary.firmware_version;
|
||||
const nameEl = row.querySelector('.col-name');
|
||||
if (nameEl && summary.device_name) nameEl.innerText = summary.device_name;
|
||||
|
||||
const modelEl = row.querySelector('.col-model');
|
||||
if (modelEl && summary.device_model) modelEl.innerText = summary.device_model;
|
||||
|
||||
const serialEl = row.querySelector('.col-serial');
|
||||
if (serialEl && summary.device_serial) serialEl.innerText = summary.device_serial;
|
||||
|
||||
const firmwareEl = row.querySelector('.col-firmware');
|
||||
if (firmwareEl && summary.firmware_version) firmwareEl.innerText = summary.firmware_version;
|
||||
}
|
||||
|
||||
document.getElementById('ssh-status').innerText = summary.ssh_success ? '✅ Success' : '❌ Failed';
|
||||
|
||||
+28
-26
@@ -112,13 +112,13 @@ func GetConfiguredSourceXML(cs models.ConfiguredSource) string {
|
||||
}
|
||||
|
||||
// PresetsToXML converts account presets to XML format for Marge responses.
|
||||
func PresetsToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
presets, err := ds.GetPresets(account)
|
||||
func PresetsToXML(ds *datastore.DataStore, account, device string) ([]byte, error) {
|
||||
presets, err := ds.GetPresets(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sources, err := ds.GetConfiguredSources(account)
|
||||
sources, err := ds.GetConfiguredSources(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,7 +135,8 @@ func PresetsToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
res += fmt.Sprintf(`<name>%s</name>`, p.Name)
|
||||
|
||||
// Content Item Source
|
||||
for _, s := range sources {
|
||||
for j := range sources {
|
||||
s := sources[j]
|
||||
if s.ID == p.SourceID || (s.SourceKeyType == p.Source && s.SourceKeyAccount == p.SourceAccount) {
|
||||
res += GetConfiguredSourceXML(s)
|
||||
break
|
||||
@@ -152,13 +153,13 @@ func PresetsToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
}
|
||||
|
||||
// RecentsToXML converts account recent items to XML format for Marge responses.
|
||||
func RecentsToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
recents, err := ds.GetRecents(account)
|
||||
func RecentsToXML(ds *datastore.DataStore, account, device string) ([]byte, error) {
|
||||
recents, err := ds.GetRecents(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sources, err := ds.GetConfiguredSources(account)
|
||||
sources, err := ds.GetConfiguredSources(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -181,7 +182,8 @@ func RecentsToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
res += fmt.Sprintf(`<name>%s</name>`, r.Name)
|
||||
|
||||
// Content Item Source
|
||||
for _, s := range sources {
|
||||
for j := range sources {
|
||||
s := sources[j]
|
||||
if s.ID == r.SourceID || (s.SourceKeyType == r.Source && s.SourceKeyAccount == r.SourceAccount) {
|
||||
res += GetConfiguredSourceXML(s)
|
||||
break
|
||||
@@ -240,12 +242,12 @@ func AccountFullToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
res += fmt.Sprintf(`<ipaddress>%s</ipaddress>`, info.IPAddress)
|
||||
res += fmt.Sprintf(`<name>%s</name>`, info.Name)
|
||||
|
||||
presets, _ := PresetsToXML(ds, account)
|
||||
presets, _ := PresetsToXML(ds, account, deviceID)
|
||||
if len(presets) > len(xml.Header) {
|
||||
res += string(presets[len(xml.Header):]) // strip header
|
||||
}
|
||||
|
||||
recents, _ := RecentsToXML(ds, account)
|
||||
recents, _ := RecentsToXML(ds, account, deviceID)
|
||||
if len(recents) > len(xml.Header) {
|
||||
res += string(recents[len(xml.Header):]) // strip header
|
||||
}
|
||||
@@ -257,11 +259,11 @@ func AccountFullToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
res += ProviderSettingsToXML(account)
|
||||
|
||||
if lastDeviceID != "" {
|
||||
sources, _ := ds.GetConfiguredSources(account)
|
||||
sources, _ := ds.GetConfiguredSources(account, lastDeviceID)
|
||||
|
||||
res += `<sources>`
|
||||
for _, s := range sources {
|
||||
res += GetConfiguredSourceXML(s)
|
||||
for j := range sources {
|
||||
res += GetConfiguredSourceXML(sources[j])
|
||||
}
|
||||
|
||||
res += `</sources>`
|
||||
@@ -273,13 +275,13 @@ func AccountFullToXML(ds *datastore.DataStore, account string) ([]byte, error) {
|
||||
}
|
||||
|
||||
// UpdatePreset updates or creates a preset for the specified account and device.
|
||||
func UpdatePreset(ds *datastore.DataStore, account, _ string, presetNumber int, sourceXML []byte) ([]byte, error) {
|
||||
sources, err := ds.GetConfiguredSources(account)
|
||||
func UpdatePreset(ds *datastore.DataStore, account, device string, presetNumber int, sourceXML []byte) ([]byte, error) {
|
||||
sources, err := ds.GetConfiguredSources(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
presets, err := ds.GetPresets(account)
|
||||
presets, err := ds.GetPresets(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -297,9 +299,9 @@ func UpdatePreset(ds *datastore.DataStore, account, _ string, presetNumber int,
|
||||
|
||||
var matchingSrc *models.ConfiguredSource
|
||||
|
||||
for _, s := range sources {
|
||||
if s.ID == newPresetElem.SourceID {
|
||||
matchingSrc = &s
|
||||
for i := range sources {
|
||||
if sources[i].ID == newPresetElem.SourceID {
|
||||
matchingSrc = &sources[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -331,7 +333,7 @@ func UpdatePreset(ds *datastore.DataStore, account, _ string, presetNumber int,
|
||||
|
||||
presets[presetNumber-1] = presetObj
|
||||
|
||||
if err := ds.SavePresets(account, presets); err != nil {
|
||||
if err := ds.SavePresets(account, device, presets); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -351,12 +353,12 @@ func UpdatePreset(ds *datastore.DataStore, account, _ string, presetNumber int,
|
||||
|
||||
// AddRecent adds or updates a recent item for the specified account and device.
|
||||
func AddRecent(ds *datastore.DataStore, account, device string, sourceXML []byte) ([]byte, error) {
|
||||
sources, err := ds.GetConfiguredSources(account)
|
||||
sources, err := ds.GetConfiguredSources(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recents, err := ds.GetRecents(account)
|
||||
recents, err := ds.GetRecents(account, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -407,7 +409,7 @@ func AddRecent(ds *datastore.DataStore, account, device string, sourceXML []byte
|
||||
}
|
||||
}
|
||||
|
||||
if err := ds.SaveRecents(account, recents); err != nil {
|
||||
if err := ds.SaveRecents(account, device, recents); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -415,9 +417,9 @@ func AddRecent(ds *datastore.DataStore, account, device string, sourceXML []byte
|
||||
}
|
||||
|
||||
func findMatchingSource(sources []models.ConfiguredSource, sourceID string) *models.ConfiguredSource {
|
||||
for _, s := range sources {
|
||||
if s.ID == sourceID {
|
||||
return &s
|
||||
for i := range sources {
|
||||
if sources[i].ID == sourceID {
|
||||
return &sources[i]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ func TestMargeXML(t *testing.T) {
|
||||
_ = ds.SaveDeviceInfo(account, device, info)
|
||||
|
||||
// Save empty presets/recents to avoid index out of range when stripping header
|
||||
_ = ds.SavePresets(account, []models.ServicePreset{})
|
||||
_ = ds.SaveRecents(account, []models.ServiceRecent{})
|
||||
_ = ds.SavePresets(account, device, []models.ServicePreset{})
|
||||
_ = ds.SaveRecents(account, device, []models.ServiceRecent{})
|
||||
|
||||
// Test SourceProvidersToXML
|
||||
xmlData, err := SourceProvidersToXML()
|
||||
@@ -78,17 +78,20 @@ func TestAddRecent_TimestampPreservation(t *testing.T) {
|
||||
|
||||
// 1. Setup configured sources
|
||||
// We need a Sources.xml file in the account directory
|
||||
sourcesPath := ds.AccountDir(account)
|
||||
_ = os.MkdirAll(sourcesPath, 0755)
|
||||
_ = ds.SaveConfiguredSources(account, []models.ConfiguredSource{
|
||||
{
|
||||
ID: "101",
|
||||
DisplayName: "Test Source",
|
||||
SourceKeyType: "TUNEIN",
|
||||
SourceKeyAccount: "test-user",
|
||||
},
|
||||
})
|
||||
_ = ds.SaveRecents(account, []models.ServiceRecent{})
|
||||
deviceDir := ds.AccountDeviceDir(account, device)
|
||||
_ = os.MkdirAll(deviceDir, 0755)
|
||||
src := models.ConfiguredSource{
|
||||
ID: "101",
|
||||
DisplayName: "Test Source",
|
||||
SecretType: "Audio",
|
||||
}
|
||||
src.SourceKey.Type = "TUNEIN"
|
||||
src.SourceKey.Account = "test-user"
|
||||
src.SourceKeyType = "TUNEIN"
|
||||
src.SourceKeyAccount = "test-user"
|
||||
|
||||
_ = ds.SaveConfiguredSources(account, device, []models.ConfiguredSource{src})
|
||||
_ = ds.SaveRecents(account, device, []models.ServiceRecent{})
|
||||
|
||||
// 2. Add an initial recent
|
||||
sourceXML := []byte(`
|
||||
@@ -104,7 +107,7 @@ func TestAddRecent_TimestampPreservation(t *testing.T) {
|
||||
t.Fatalf("AddRecent failed: %v", err)
|
||||
}
|
||||
|
||||
recents, _ := ds.GetRecents(account)
|
||||
recents, _ := ds.GetRecents(account, device)
|
||||
if len(recents) != 1 {
|
||||
t.Fatalf("Expected 1 recent, got %d", len(recents))
|
||||
}
|
||||
@@ -126,7 +129,7 @@ func TestAddRecent_TimestampPreservation(t *testing.T) {
|
||||
t.Errorf("Expected preserved DateStr in createdOn, got XML: %s", string(respXML))
|
||||
}
|
||||
|
||||
recents, _ = ds.GetRecents(account)
|
||||
recents, _ = ds.GetRecents(account, device)
|
||||
if len(recents) != 1 {
|
||||
t.Errorf("Expected still 1 recent, got %d", len(recents))
|
||||
}
|
||||
|
||||
+190
-1
@@ -8,8 +8,11 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gesellix/bose-soundtouch/pkg/models"
|
||||
|
||||
"github.com/gesellix/bose-soundtouch/pkg/service/certmanager"
|
||||
"github.com/gesellix/bose-soundtouch/pkg/service/datastore"
|
||||
"github.com/gesellix/bose-soundtouch/pkg/service/ssh"
|
||||
@@ -247,7 +250,8 @@ func (m *Manager) populateDeviceInfo(summary *MigrationSummary, deviceIP string)
|
||||
if m.DataStore != nil {
|
||||
devices, err := m.DataStore.ListAllDevices()
|
||||
if err == nil {
|
||||
for _, d := range devices {
|
||||
for i := range devices {
|
||||
d := devices[i]
|
||||
if d.IPAddress != deviceIP {
|
||||
continue
|
||||
}
|
||||
@@ -984,3 +988,188 @@ func (m *Manager) resolveIP(host string, client SSHClient) string {
|
||||
|
||||
return ips[0].String()
|
||||
}
|
||||
|
||||
// SyncDeviceData fetches presets, recents and sources from the device and saves them to the datastore.
|
||||
func (m *Manager) SyncDeviceData(deviceIP string) error {
|
||||
// 1. Fetch info to get Serial Number (account identifier)
|
||||
info, err := m.GetLiveDeviceInfo(deviceIP)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get device info: %w", err)
|
||||
}
|
||||
|
||||
accountID := "default"
|
||||
|
||||
deviceID := info.SerialNumber
|
||||
if deviceID == "" {
|
||||
deviceID = deviceIP
|
||||
}
|
||||
|
||||
// 2. Fetch Presets from :8090
|
||||
m.syncPresets(deviceIP, accountID, deviceID)
|
||||
|
||||
// 3. Fetch Recents from :8090
|
||||
m.syncRecents(deviceIP, accountID, deviceID)
|
||||
|
||||
// 4. Fetch Sources
|
||||
m.syncSources(deviceIP, accountID, deviceID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) syncPresets(deviceIP, accountID, deviceID string) {
|
||||
presetsURL := fmt.Sprintf("http://%s:8090/presets", deviceIP)
|
||||
if _, _, splitErr := net.SplitHostPort(deviceIP); splitErr == nil {
|
||||
presetsURL = fmt.Sprintf("http://%s/presets", deviceIP)
|
||||
}
|
||||
|
||||
resp, err := http.Get(presetsURL)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
var ps models.Presets
|
||||
if decodeErr := xml.NewDecoder(resp.Body).Decode(&ps); decodeErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var servicePresets []models.ServicePreset
|
||||
|
||||
for _, p := range ps.Preset {
|
||||
if p.ContentItem == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
createdOn := ""
|
||||
if p.CreatedOn != nil {
|
||||
createdOn = strconv.FormatInt(*p.CreatedOn, 10)
|
||||
}
|
||||
|
||||
updatedOn := ""
|
||||
if p.UpdatedOn != nil {
|
||||
updatedOn = strconv.FormatInt(*p.UpdatedOn, 10)
|
||||
}
|
||||
|
||||
servicePresets = append(servicePresets, models.ServicePreset{
|
||||
ServiceContentItem: models.ServiceContentItem{
|
||||
ID: strconv.Itoa(p.ID),
|
||||
Name: p.ContentItem.ItemName,
|
||||
Source: p.ContentItem.Source,
|
||||
Type: p.ContentItem.Type,
|
||||
Location: p.ContentItem.Location,
|
||||
SourceAccount: p.ContentItem.SourceAccount,
|
||||
SourceID: "", // Preset doesn't have SourceID in ContentItem usually
|
||||
IsPresetable: strconv.FormatBool(p.ContentItem.IsPresetable),
|
||||
},
|
||||
ContainerArt: p.ContentItem.ContainerArt,
|
||||
CreatedOn: createdOn,
|
||||
UpdatedOn: updatedOn,
|
||||
})
|
||||
}
|
||||
|
||||
_ = m.DataStore.SavePresets(accountID, deviceID, servicePresets)
|
||||
}
|
||||
|
||||
func (m *Manager) syncRecents(deviceIP, accountID, deviceID string) {
|
||||
recentsURL := fmt.Sprintf("http://%s:8090/recents", deviceIP)
|
||||
if _, _, splitErr := net.SplitHostPort(deviceIP); splitErr == nil {
|
||||
recentsURL = fmt.Sprintf("http://%s/recents", deviceIP)
|
||||
}
|
||||
|
||||
resp, err := http.Get(recentsURL)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
var rr models.RecentsResponse
|
||||
if decodeErr := xml.NewDecoder(resp.Body).Decode(&rr); decodeErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var serviceRecents []models.ServiceRecent
|
||||
|
||||
for _, r := range rr.Items {
|
||||
if r.ContentItem == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
serviceRecents = append(serviceRecents, models.ServiceRecent{
|
||||
ServiceContentItem: models.ServiceContentItem{
|
||||
ID: r.ID,
|
||||
Name: r.ContentItem.ItemName,
|
||||
Source: r.ContentItem.Source,
|
||||
Type: r.ContentItem.Type,
|
||||
Location: r.ContentItem.Location,
|
||||
SourceAccount: r.ContentItem.SourceAccount,
|
||||
SourceID: "", // RecentsResponseItem doesn't have SourceID usually
|
||||
IsPresetable: strconv.FormatBool(r.ContentItem.IsPresetable),
|
||||
},
|
||||
DeviceID: r.DeviceID,
|
||||
UtcTime: strconv.FormatInt(r.UTCTime, 10),
|
||||
ContainerArt: r.ContentItem.ContainerArt,
|
||||
})
|
||||
}
|
||||
|
||||
_ = m.DataStore.SaveRecents(accountID, deviceID, serviceRecents)
|
||||
}
|
||||
|
||||
func (m *Manager) syncSources(deviceIP, accountID, deviceID string) {
|
||||
client := m.NewSSH(deviceIP)
|
||||
|
||||
sourcesXML, err := client.Run("cat /mnt/nv/BoseApp-Persistence/1/Sources.xml")
|
||||
if err == nil && sourcesXML != "" {
|
||||
var srs struct {
|
||||
Sources []models.ConfiguredSource `xml:"source"`
|
||||
}
|
||||
if xmlErr := xml.Unmarshal([]byte(sourcesXML), &srs); xmlErr == nil {
|
||||
// After unmarshaling from SSH, ensure legacy fields are synced for internal use
|
||||
for i := range srs.Sources {
|
||||
s := &srs.Sources[i]
|
||||
s.SourceKeyType = s.SourceKey.Type
|
||||
s.SourceKeyAccount = s.SourceKey.Account
|
||||
}
|
||||
|
||||
_ = m.DataStore.SaveConfiguredSources(accountID, deviceID, srs.Sources)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to :8090/sources
|
||||
sourcesURL := fmt.Sprintf("http://%s:8090/sources", deviceIP)
|
||||
if _, _, splitErr := net.SplitHostPort(deviceIP); splitErr == nil {
|
||||
sourcesURL = fmt.Sprintf("http://%s/sources", deviceIP)
|
||||
}
|
||||
|
||||
resp, err := http.Get(sourcesURL)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
var srs models.Sources
|
||||
if decodeErr := xml.NewDecoder(resp.Body).Decode(&srs); decodeErr == nil {
|
||||
var configuredSources []models.ConfiguredSource
|
||||
|
||||
for _, s := range srs.SourceItem {
|
||||
cs := models.ConfiguredSource{
|
||||
DisplayName: s.DisplayName,
|
||||
ID: s.Source,
|
||||
SecretType: string(s.Status),
|
||||
}
|
||||
cs.SourceKey.Type = s.Source
|
||||
cs.SourceKey.Account = s.SourceAccount
|
||||
// Also set legacy fields for now
|
||||
cs.SourceKeyType = s.Source
|
||||
cs.SourceKeyAccount = s.SourceAccount
|
||||
|
||||
configuredSources = append(configuredSources, cs)
|
||||
}
|
||||
|
||||
_ = m.DataStore.SaveConfiguredSources(accountID, deviceID, configuredSources)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user