- Port now supports mihomo ports format (single/range/list) - Add explicit RoutingMark field support - Auto-propagate UDP flag for vmess/vless/trojan/anytls/trusttunnel - Update validator to accept port ranges - Sync visual config and client converter port types - Rename module from dzx941 to kazeyukiro - Fix missing ExpiresAt in JWTClaims - Fix nodeDTO Port type to string - Fix frontend tsconfig and add missing dependencies
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package node
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/kazeyukiro/3m-ui/backend/internal/database/models"
|
|
"github.com/kazeyukiro/3m-ui/backend/internal/user"
|
|
)
|
|
|
|
// ClientURIsWithCredentials bridges node URI export with the canonical
|
|
// credential service. Listener.Config is server configuration and is not the
|
|
// source of truth for users managed by 3m-ui.
|
|
func ClientURIsWithCredentials(listener models.Listener, host string, credentials []user.Credential) ([]string, error) {
|
|
var cfg map[string]interface{}
|
|
if listener.Config != "" {
|
|
if err := json.Unmarshal([]byte(listener.Config), &cfg); err != nil {
|
|
return nil, fmt.Errorf("invalid listener configuration: %w", err)
|
|
}
|
|
}
|
|
if cfg == nil {
|
|
cfg = map[string]interface{}{}
|
|
}
|
|
if len(credentials) > 0 {
|
|
switch listener.Protocol {
|
|
case "anytls", "hysteria2", "mieru", "tuic":
|
|
users := make(map[string]interface{}, len(credentials))
|
|
for _, credential := range credentials {
|
|
if credential.Username != "" {
|
|
users[credential.Username] = credential.Password
|
|
}
|
|
}
|
|
cfg["users"] = users
|
|
default:
|
|
users := make([]interface{}, 0, len(credentials))
|
|
for _, credential := range credentials {
|
|
users = append(users, map[string]interface{}{"username": credential.Username, "password": credential.Password, "uuid": credential.UUID})
|
|
}
|
|
cfg["users"] = users
|
|
}
|
|
if listener.Protocol == "shadowsocks" {
|
|
cfg["password"] = credentials[0].Password
|
|
}
|
|
}
|
|
encoded, err := json.Marshal(cfg)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to prepare URI configuration: %w", err)
|
|
}
|
|
listener.Config = string(encoded)
|
|
return ClientURIs(listener, host)
|
|
}
|