mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-24 11:57:15 +00:00
feat(pia): add PIA login-and-add WireGuard outbounds (#6272)
* feat(pia): add login-and-add WireGuard outbounds (#2) * fix(pia): keep PIA outbounds identifiable after the editor strips hostname The outbound editor drops piaHostname, so last-segment matching failed for hyphenated servers. Identify rows by the computed tag, re-encrypt stored tokens onto the active key, skip unusable catalog rows, and always release the catalog refresh latch.
This commit is contained in:
@@ -2,11 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
piaprotocol "github.com/mhsanaei/3x-ui/v3/internal/pia"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/common"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/web/service/integration"
|
||||
@@ -25,13 +27,14 @@ type XraySettingController struct {
|
||||
XrayService service.XrayService
|
||||
WarpService integration.WarpService
|
||||
NordService integration.NordService
|
||||
PiaService integration.PiaService
|
||||
OutboundSubscriptionService service.OutboundSubscriptionService
|
||||
GeodataService service.GeodataService
|
||||
}
|
||||
|
||||
// NewXraySettingController creates a new XraySettingController and initializes its routes.
|
||||
func NewXraySettingController(g *gin.RouterGroup) *XraySettingController {
|
||||
a := &XraySettingController{}
|
||||
a := &XraySettingController{PiaService: *integration.NewPiaService()}
|
||||
a.initRouter(g)
|
||||
return a
|
||||
}
|
||||
@@ -46,6 +49,7 @@ func (a *XraySettingController) initRouter(g *gin.RouterGroup) {
|
||||
g.POST("/", a.getXraySetting)
|
||||
g.POST("/warp/:action", a.warp)
|
||||
g.POST("/nord/:action", a.nord)
|
||||
g.POST("/pia/:action", a.pia)
|
||||
g.POST("/update", a.updateSetting)
|
||||
g.POST("/resetOutboundsTraffic", a.resetOutboundsTraffic)
|
||||
g.POST("/testOutbound", a.testOutbound)
|
||||
@@ -241,6 +245,39 @@ func (a *XraySettingController) nord(c *gin.Context) {
|
||||
jsonObj(c, resp, err)
|
||||
}
|
||||
|
||||
func (a *XraySettingController) pia(c *gin.Context) {
|
||||
action := c.Param("action")
|
||||
var resp any
|
||||
var err error
|
||||
switch action {
|
||||
case "countries":
|
||||
resp, err = a.PiaService.GetCountries()
|
||||
case "servers":
|
||||
resp, err = a.PiaService.GetServers(c.PostForm("countryCode"))
|
||||
case "reg":
|
||||
resp, err = a.PiaService.Login(c.PostForm("username"), c.PostForm("password"))
|
||||
case "data":
|
||||
resp, err = a.PiaService.GetPiaData()
|
||||
case "del":
|
||||
err = a.PiaService.DelPiaData()
|
||||
case "addKey":
|
||||
resp, err = a.PiaService.AddKey(c.PostForm("hostname"))
|
||||
default:
|
||||
jsonMsg(c, "unknown action", common.NewError("unknown action"))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
var pe *piaprotocol.Error
|
||||
if errors.As(err, &pe) && pe != nil {
|
||||
jsonObj(c, nil, common.NewError(pe.Message))
|
||||
return
|
||||
}
|
||||
jsonObj(c, nil, err)
|
||||
return
|
||||
}
|
||||
jsonObj(c, resp, nil)
|
||||
}
|
||||
|
||||
// getOutboundsTraffic retrieves the traffic statistics for outbounds.
|
||||
func (a *XraySettingController) getOutboundsTraffic(c *gin.Context) {
|
||||
outboundsTraffic, err := a.OutboundService.GetOutboundsTraffic()
|
||||
|
||||
Reference in New Issue
Block a user