diff --git a/server/internal/services/servers.go b/server/internal/services/servers.go index c1b62b5..4a5946c 100644 --- a/server/internal/services/servers.go +++ b/server/internal/services/servers.go @@ -122,25 +122,27 @@ func RegisterServer(serverID, preRegToken, hostname, ipAddress, osInfo string) ( osType := OSTypeFromInfo(osInfo) protocols, sshPort, rdpPort := defaultConsoleFields(osType) + setFields := bson.M{ + "hostname": hostname, + "ip_address": ipAddress, + "os_info": osInfo, + "os_type": osType, + "agent_token_hash": tokenHash, + "status": "active", + "last_seen": now, + "pre_reg_token": "", + "pre_reg_expires": nil, + } + if len(s.ConsoleProtocols) == 0 { + setFields["console_protocols"] = protocols + setFields["ssh_port"] = sshPort + setFields["rdp_port"] = rdpPort + } + _, err = db.Col("servers").UpdateOne(ctx, bson.M{"server_id": serverID}, bson.M{ - "$set": bson.M{ - "hostname": hostname, - "ip_address": ipAddress, - "os_info": osInfo, - "os_type": osType, - "agent_token_hash": tokenHash, - "status": "active", - "last_seen": now, - "pre_reg_token": "", - "pre_reg_expires": nil, - }, - "$setOnInsert": bson.M{ - "console_protocols": protocols, - "ssh_port": sshPort, - "rdp_port": rdpPort, - }, + "$set": setFields, }, ) if err != nil {