Browse Source

bug fix

Co-Authored-By: Alireza Ahmadi <[email protected]>
MHSanaei 1 year ago
parent
commit
7412bf17a9

+ 3 - 3
web/assets/js/model/xray.js

@@ -1636,7 +1636,7 @@ Inbound.VLESSSettings = class extends Inbound.Settings {
     toJson() {
         return {
             clients: Inbound.VLESSSettings.toJsonArray(this.vlesses),
-            decryption: this.decryption,
+            decryption: 'none',
             fallbacks: Inbound.VLESSSettings.toJsonArray(this.fallbacks),
         };
     }
@@ -1696,7 +1696,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
     }
 };
 Inbound.VLESSSettings.Fallback = class extends XrayCommonClass {
-    constructor(name="", alpn=[], path='', dest='', xver=0) {
+    constructor(name="", alpn='', path='', dest='', xver=0) {
         super();
         this.name = name;
         this.alpn = alpn;
@@ -1835,7 +1835,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
 };
 
 Inbound.TrojanSettings.Fallback = class extends XrayCommonClass {
-    constructor(name="", alpn=[], path='', dest='', xver=0) {
+    constructor(name="", alpn='', path='', dest='', xver=0) {
         super();
         this.name = name;
         this.alpn = alpn;

+ 25 - 0
web/controller/server.go

@@ -39,6 +39,8 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
 	g.POST("/restartXrayService", a.restartXrayService)
 	g.POST("/installXray/:version", a.installXray)
 	g.POST("/logs/:count", a.getLogs)
+	g.POST("/getConfigJson", a.getConfigJson)
+	g.GET("/getDb", a.getDb)
 }
 
 func (a *ServerController) refreshStatus() {
@@ -117,3 +119,26 @@ func (a *ServerController) getLogs(c *gin.Context) {
 	}
 	jsonObj(c, logs, nil)
 }
+
+func (a *ServerController) getConfigJson(c *gin.Context) {
+	configJson, err := a.serverService.GetConfigJson()
+	if err != nil {
+		jsonMsg(c, I18n(c, "getLogs"), err)
+		return
+	}
+	jsonObj(c, configJson, nil)
+}
+
+func (a *ServerController) getDb(c *gin.Context) {
+	db, err := a.serverService.GetDb()
+	if err != nil {
+		jsonMsg(c, I18n(c, "getLogs"), err)
+		return
+	}
+	// Set the headers for the response
+	c.Header("Content-Type", "application/octet-stream")
+	c.Header("Content-Disposition", "attachment; filename=xui.db")
+
+	// Write the file contents to the response
+	c.Writer.Write(db)
+}

+ 1 - 1
web/html/xui/inbound_info_modal.html

@@ -240,7 +240,7 @@
                 return infoModal.dbInbound.isEnable;
             },
             get subBase() {
-                return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port:"") + "/sub/";
+                return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port:"") + basePath + "sub/";
             },
             get tgBase() {
                 return "https://t.me/"

+ 36 - 16
web/html/xui/index.html

@@ -74,6 +74,25 @@
             </transition>
             <transition name="list" appear>
                 <a-row>
+                    <a-col :sm="24" :md="12">
+                        <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
+                            3x-ui: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
+                            Xray: <a-tag color="green" style="cursor: pointer;" @click="openSelectV2rayVersion">v[[ status.xray.version ]]</a-tag>
+                            Telegram: <a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">@panel3xui</a-tag></a>
+                        </a-card>
+                    </a-col>
+                    <a-col :sm="24" :md="12">
+                        <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
+                            {{ i18n "pages.index.operationHours" }}:
+                            <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
+                            <a-tooltip>
+                                <template slot="title">
+                                    {{ i18n "pages.index.operationHoursDesc" }}
+                                </template>
+                                <a-icon type="question-circle" theme="filled"></a-icon>
+                            </a-tooltip>
+                        </a-card>
+                    </a-col>
                     <a-col :sm="24" :md="12">
                         <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
                             {{ i18n "pages.index.xrayStatus" }}:
@@ -84,7 +103,6 @@
                                 </template>
                                 <a-icon type="question-circle" theme="filled"></a-icon>
                             </a-tooltip>
-                            <a-tag color="green" style="cursor: pointer;" @click="openSelectV2rayVersion">[[ status.xray.version ]]</a-tag>
                             <a-tag color="blue" style="cursor: pointer;" @click="stopXrayService">{{ i18n "pages.index.stopXray" }}</a-tag>
                             <a-tag color="blue" style="cursor: pointer;" @click="restartXrayService">{{ i18n "pages.index.restartXray" }}</a-tag>                    
                             <a-tag color="blue" style="cursor: pointer;" @click="openSelectV2rayVersion">{{ i18n "pages.index.xraySwitch" }}</a-tag>
@@ -92,14 +110,10 @@
                     </a-col>
                     <a-col :sm="24" :md="12">
                         <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
-                            {{ i18n "pages.index.operationHours" }}:
-                            <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
-                            <a-tooltip>
-                                <template slot="title">
-                                    {{ i18n "pages.index.operationHoursDesc" }}
-                                </template>
-                                <a-icon type="question-circle" theme="filled"></a-icon>
-                            </a-tooltip>
+                            {{ i18n "menu.link" }}:
+                            <a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">Log Reports</a-tag>
+                            <a-tag color="blue" style="cursor: pointer;" @click="openConfig">Config</a-tag>
+                            <a-tag color="blue" style="cursor: pointer;" @click="getBackup">Backup</a-tag>
                         </a-card>
                     </a-col>
                     <a-col :sm="24" :md="12">
@@ -169,13 +183,6 @@
                                 </a-col>
                             </a-row>
                         </a-card>
-                    </a-col>
-					<a-col :sm="24" :md="12">
-                        <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
-							 3x-ui: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
-							<a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">Telegram</a-tag></a>
-							<a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">Log Reports</a-tag>
-                        </a-card>
                     </a-col>
                 </a-row>
             </transition>
@@ -226,6 +233,7 @@
     </a-modal>
 </a-layout>
 {{template "js" .}}
+{{template "textModal"}}
 <script>
 
     const State = {
@@ -406,6 +414,18 @@
                     return;
                 }
                 logModal.show(msg.obj,rows);
+            },
+            async openConfig(){
+                this.loading(true);
+                const msg = await HttpUtil.post('server/getConfigJson');
+                this.loading(false);
+                if (!msg.success) {
+                    return;
+                }
+                txtModal.show('config.json',JSON.stringify(msg.obj, null, 2),'config.json');
+            },
+            getBackup(){
+                window.location = basePath + 'server/getDb';
             }
         },
         async mounted() {

+ 12 - 10
web/service/inbound.go

@@ -454,19 +454,21 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr
 			continue
 		}
 		// get settings clients
-		settings := map[string][]model.Client{}
+		settings := map[string]interface{}{}
 		json.Unmarshal([]byte(inbound.Settings), &settings)
-		clients := settings["clients"]
+		clients, ok := settings["clients"].([]model.Client)
 		needUpdate := false
-		for client_index, client := range clients {
-			if traffic.Email == client.Email {
-				if client.ExpiryTime < 0 {
-					clients[client_index].ExpiryTime = (time.Now().Unix() * 1000) - client.ExpiryTime
-					needUpdate = true
+		if ok {
+			for client_index, client := range clients {
+				if traffic.Email == client.Email {
+					if client.ExpiryTime < 0 {
+						clients[client_index].ExpiryTime = (time.Now().Unix() * 1000) - client.ExpiryTime
+						needUpdate = true
+					}
+					client_traffic.ExpiryTime = client.ExpiryTime
+					client_traffic.Total = client.TotalGB
+					break
 				}
-				client_traffic.ExpiryTime = client.ExpiryTime
-				client_traffic.Total = client.TotalGB
-				break
 			}
 		}
 

+ 41 - 0
web/service/server.go

@@ -13,6 +13,7 @@ import (
 	"runtime"
 	"strings"
 	"time"
+	"x-ui/config"
 	"x-ui/logger"
 	"x-ui/util/sys"
 	"x-ui/xray"
@@ -349,3 +350,43 @@ func (s *ServerService) GetLogs(count string) ([]string, error) {
 
 	return lines, nil
 }
+
+func (s *ServerService) GetConfigJson() (interface{}, error) {
+	// Open the file for reading
+	file, err := os.Open(xray.GetConfigPath())
+	if err != nil {
+		return nil, err
+	}
+	defer file.Close()
+
+	// Read the file contents
+	fileContents, err := io.ReadAll(file)
+	if err != nil {
+		return nil, err
+	}
+
+	var jsonData interface{}
+	err = json.Unmarshal(fileContents, &jsonData)
+	if err != nil {
+		return nil, err
+	}
+
+	return jsonData, nil
+}
+
+func (s *ServerService) GetDb() ([]byte, error) {
+	// Open the file for reading
+	file, err := os.Open(config.GetDBPath())
+	if err != nil {
+		return nil, err
+	}
+	defer file.Close()
+
+	// Read the file contents
+	fileContents, err := io.ReadAll(file)
+	if err != nil {
+		return nil, err
+	}
+
+	return fileContents, nil
+}