mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-13 09:36:05 +00:00
- New GET /panel/api/inbounds/getSubLinks/:subId and /getClientLinks/:id/:email return the same protocol URLs the panel UI's Copy button emits, honouring X-Forwarded-Host / X-Forwarded-Proto. Documented in the API docs page. - Refactor: sub package no longer imports web. The embedded dist FS is injected via sub.SetDistFS, and the link generator is registered with the service layer via service.RegisterSubLinkProvider, avoiding the circular import the new endpoints would otherwise introduce. - Security: stop emitting window.X_UI_CUR_VER on login.html and drop the visible version chip from the login page, so the panel version is no longer pre-auth info disclosure. Authenticated pages still receive it. - Bump config/version.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package sub
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/web/service"
|
|
)
|
|
|
|
type LinkProvider struct {
|
|
settingService service.SettingService
|
|
}
|
|
|
|
func NewLinkProvider() *LinkProvider {
|
|
return &LinkProvider{}
|
|
}
|
|
|
|
func (p *LinkProvider) build(host string) *SubService {
|
|
showInfo, _ := p.settingService.GetSubShowInfo()
|
|
rModel, err := p.settingService.GetRemarkModel()
|
|
if err != nil {
|
|
rModel = "-ieo"
|
|
}
|
|
svc := NewSubService(showInfo, rModel)
|
|
svc.PrepareForRequest(host)
|
|
return svc
|
|
}
|
|
|
|
func (p *LinkProvider) SubLinksForSubId(host, subId string) ([]string, error) {
|
|
svc := p.build(host)
|
|
links, _, _, err := svc.GetSubs(subId, host)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]string, 0, len(links))
|
|
for _, l := range links {
|
|
out = append(out, splitLinkLines(l)...)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (p *LinkProvider) LinksForClient(host string, inbound *model.Inbound, email string) []string {
|
|
svc := p.build(host)
|
|
return splitLinkLines(svc.GetLink(inbound, email))
|
|
}
|
|
|
|
func splitLinkLines(raw string) []string {
|
|
if raw == "" {
|
|
return nil
|
|
}
|
|
parts := strings.Split(raw, "\n")
|
|
out := make([]string, 0, len(parts))
|
|
for _, p := range parts {
|
|
if p = strings.TrimSpace(p); p != "" {
|
|
out = append(out, p)
|
|
}
|
|
}
|
|
return out
|
|
}
|