mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
PostImport, PutPorts, PutDnsRules, PutRoutingA, PutGFWList,
DeleteGFWList, PutDomainsExcluded, PutTproxyWhiteIpGroups, PostOutbound
and PutOutbound wrote the store and regenerated the core outside the
mutation turn, so two of them could interleave core restarts with each
other or with a latency test. They take it like the rest.
ParseSSURL and ParseVmessURL sliced past the end of a link shorter than
its scheme prefix ("ss:", "vmess:x"), a panic reachable from a
subscription line.
100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"github.com/v2rayA/v2rayA/db/configure"
|
|
"github.com/v2rayA/v2rayA/kernel/serverObj"
|
|
"github.com/v2rayA/v2rayA/kernel/v2ray"
|
|
"github.com/v2rayA/v2rayA/server/service"
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func getHostnameFromHost(host string) string {
|
|
i := strings.LastIndex(host, ":")
|
|
if _, err := strconv.Atoi(host[i+1:]); err != nil {
|
|
return host
|
|
}
|
|
h, _, err := net.SplitHostPort(host)
|
|
if err != nil {
|
|
return host
|
|
}
|
|
return h
|
|
}
|
|
|
|
func PutPorts(ctx *gin.Context) {
|
|
release, ok := beginMutation(ctx)
|
|
if !ok {
|
|
return
|
|
}
|
|
defer release()
|
|
var data configure.Ports
|
|
err := ctx.ShouldBindJSON(&data)
|
|
if err != nil {
|
|
common.ResponseError(ctx, badRequest("ports", "request body is not a valid ports object"))
|
|
return
|
|
}
|
|
origin := service.GetPorts()
|
|
err = service.SetPorts(&data)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
// if is turning VLESS-GRPC on
|
|
if data.Vmess > 0 && origin.Vmess <= 0 {
|
|
link, err := getLinkForVmess(ctx.Request.Host)
|
|
if err != nil {
|
|
common.ResponseError(ctx, err)
|
|
return
|
|
}
|
|
common.ResponseSuccess(ctx, gin.H{
|
|
"vmessLink": link,
|
|
})
|
|
return
|
|
}
|
|
common.ResponseSuccess(ctx, nil)
|
|
}
|
|
|
|
func getLinkForVmess(host string) (string, error) {
|
|
return _getLinkForVmess(getHostnameFromHost(host))
|
|
}
|
|
|
|
func GetPorts(ctx *gin.Context) {
|
|
var data struct {
|
|
configure.Ports
|
|
VmessLink *string `json:"vmessLink"`
|
|
}
|
|
data.Ports = service.GetPorts()
|
|
if data.Vmess > 0 {
|
|
link, err := getLinkForVmess(ctx.Request.Host)
|
|
if err != nil {
|
|
common.ResponseError(ctx, err)
|
|
return
|
|
}
|
|
data.VmessLink = &link
|
|
}
|
|
common.ResponseSuccess(ctx, data)
|
|
}
|
|
|
|
func _getLinkForVmess(hostname string) (link string, err error) {
|
|
id, err := v2ray.GenerateIdFromAccounts()
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to generate link for VLESS-GRPC inbound: %w", err)
|
|
}
|
|
p := service.GetPorts()
|
|
info := serverObj.V2Ray{
|
|
Ps: "VMess | v2rayA",
|
|
Add: hostname,
|
|
Port: strconv.Itoa(p.Vmess),
|
|
ID: id,
|
|
Aid: "0",
|
|
Net: "tcp",
|
|
V: "2",
|
|
Protocol: "vmess",
|
|
}
|
|
return info.ExportToURL(), nil
|
|
}
|