Skip to content

Commit 77b84d2

Browse files
Fix Proxmox API: use strings.HasPrefix for safe protocol check
1 parent 7f3eada commit 77b84d2

1 file changed

Lines changed: 5 additions & 17 deletions

File tree

src/proxmoxAPI.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"strings"
89
"time"
910

1011
"github.com/azukaar/cosmos-server/src/utils"
@@ -67,7 +68,7 @@ func TestProxmoxConnectionRoute(w http.ResponseWriter, req *http.Request) {
6768

6869
// Build API URL - handle both with and without protocol
6970
host := request.Host
70-
if host[0:4] != "http" {
71+
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") {
7172
host = "https://" + host
7273
}
7374
apiURL := fmt.Sprintf("%s/api2/json/version", host)
@@ -168,9 +169,9 @@ func TestProxmoxConnectionRoute(w http.ResponseWriter, req *http.Request) {
168169
for _, s := range storageData.Data {
169170
// Only include storage that can hold rootdir or images
170171
if s.Content == "" ||
171-
contains(s.Content, "rootdir") ||
172-
contains(s.Content, "images") ||
173-
contains(s.Content, "vztmpl") {
172+
strings.Contains(s.Content, "rootdir") ||
173+
strings.Contains(s.Content, "images") ||
174+
strings.Contains(s.Content, "vztmpl") {
174175
storageNames = append(storageNames, s.Storage)
175176
}
176177
}
@@ -187,16 +188,3 @@ func TestProxmoxConnectionRoute(w http.ResponseWriter, req *http.Request) {
187188
Storages: storageNames,
188189
})
189190
}
190-
191-
func contains(s, substr string) bool {
192-
return len(s) >= len(substr) && (s == substr || len(s) > 0 && containsImpl(s, substr))
193-
}
194-
195-
func containsImpl(s, substr string) bool {
196-
for i := 0; i <= len(s)-len(substr); i++ {
197-
if s[i:i+len(substr)] == substr {
198-
return true
199-
}
200-
}
201-
return false
202-
}

0 commit comments

Comments
 (0)