Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-05-25 02:41:09 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-05-25 02:41:09 +0300
commit896cc5386c53673a25b33d7917cf952c123a3db1 (patch)
tree67074066fe105406453e2628533a1b116f2ddf03 /web/service
parent76f70ce1e93ccc977907acafdafbef6b14dc79e7 (diff)
new - show cores, public ipv4 and ipv6
logical Processors you can see them on first page
Diffstat (limited to 'web/service')
-rw-r--r--web/service/server.go49
1 files changed, 46 insertions, 3 deletions
diff --git a/web/service/server.go b/web/service/server.go
index d0ca6e21..cace8eba 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -38,9 +38,11 @@ const (
)
type Status struct {
- T time.Time `json:"-"`
- Cpu float64 `json:"cpu"`
- Mem struct {
+ T time.Time `json:"-"`
+ Cpu float64 `json:"cpu"`
+ CpuCores int `json:"cpuCores"`
+ LogicalProcessors int `json:"logicalProcessors"`
+ Mem struct {
Current uint64 `json:"current"`
Total uint64 `json:"total"`
} `json:"mem"`
@@ -69,6 +71,10 @@ type Status struct {
Sent uint64 `json:"sent"`
Recv uint64 `json:"recv"`
} `json:"netTraffic"`
+ PublicIP struct {
+ IPv4 string `json:"ipv4"`
+ IPv6 string `json:"ipv6"`
+ } `json:"publicIP"`
}
type Release struct {
@@ -80,6 +86,33 @@ type ServerService struct {
inboundService InboundService
}
+const DebugMode = false // Set to true during development
+
+func getPublicIP(url string) string {
+ resp, err := http.Get(url)
+ if err != nil {
+ if DebugMode {
+ logger.Warning("get public IP failed:", err)
+ }
+ return "N/A"
+ }
+ defer resp.Body.Close()
+
+ ip, err := io.ReadAll(resp.Body)
+ if err != nil {
+ if DebugMode {
+ logger.Warning("read public IP failed:", err)
+ }
+ return "N/A"
+ }
+
+ if string(ip) == "" {
+ return "N/A" // default value
+ }
+
+ return string(ip)
+}
+
func (s *ServerService) GetStatus(lastStatus *Status) *Status {
now := time.Now()
status := &Status{
@@ -93,6 +126,13 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
status.Cpu = percents[0]
}
+ status.CpuCores, err = cpu.Counts(false)
+ if err != nil {
+ logger.Warning("get cpu cores count failed:", err)
+ }
+
+ status.LogicalProcessors = runtime.NumCPU()
+
upTime, err := host.Uptime()
if err != nil {
logger.Warning("get uptime failed:", err)
@@ -161,6 +201,9 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
logger.Warning("get udp connections failed:", err)
}
+ status.PublicIP.IPv4 = getPublicIP("https://api.ipify.org")
+ status.PublicIP.IPv6 = getPublicIP("https://api6.ipify.org")
+
if s.xrayService.IsXrayRunning() {
status.Xray.State = Running
status.Xray.ErrorMsg = ""