mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-24 20:06:52 +00:00
add outbound traffic reset (#1767)
This commit is contained in:
parent
2d354eafa3
commit
3519fe657c
3 changed files with 52 additions and 2 deletions
|
@ -29,6 +29,7 @@ func (a *XraySettingController) initRouter(g *gin.RouterGroup) {
|
||||||
g.GET("/getDefaultJsonConfig", a.getDefaultXrayConfig)
|
g.GET("/getDefaultJsonConfig", a.getDefaultXrayConfig)
|
||||||
g.POST("/warp/:action", a.warp)
|
g.POST("/warp/:action", a.warp)
|
||||||
g.GET("/getOutboundsTraffic", a.getOutboundsTraffic)
|
g.GET("/getOutboundsTraffic", a.getOutboundsTraffic)
|
||||||
|
g.POST("/resetOutboundsTraffic", a.resetOutboundsTraffic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *XraySettingController) getXraySetting(c *gin.Context) {
|
func (a *XraySettingController) getXraySetting(c *gin.Context) {
|
||||||
|
@ -95,3 +96,13 @@ func (a *XraySettingController) getOutboundsTraffic(c *gin.Context) {
|
||||||
}
|
}
|
||||||
jsonObj(c, outboundsTraffic, nil)
|
jsonObj(c, outboundsTraffic, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *XraySettingController) resetOutboundsTraffic(c *gin.Context) {
|
||||||
|
tag := c.PostForm("tag")
|
||||||
|
err := a.OutboundService.ResetOutboundTraffic(tag)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "Error in reset outbound traffics", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonObj(c, "", nil)
|
||||||
|
}
|
||||||
|
|
|
@ -385,11 +385,13 @@
|
||||||
<a-tab-pane key="tpl-3" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
|
<a-tab-pane key="tpl-3" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
|
||||||
<a-row>
|
<a-row>
|
||||||
<a-col :xs="12" :sm="12" :lg="12">
|
<a-col :xs="12" :sm="12" :lg="12">
|
||||||
<a-button type="primary" icon="plus" @click="addOutbound()" style="margin-bottom: 10px;">{{ i18n "pages.xray.outbound.addOutbound" }}</a-button>
|
<a-button type="primary" icon="plus" @click="addOutbound()" style="margin-bottom: 10px;">{{ i18n
|
||||||
|
"pages.xray.outbound.addOutbound" }}</a-button>
|
||||||
<a-button type="primary" @click="showWarp()" style="margin-bottom: 10px;">WARP</a-button>
|
<a-button type="primary" @click="showWarp()" style="margin-bottom: 10px;">WARP</a-button>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :xs="12" :sm="12" :lg="12" style="text-align: right;">
|
<a-col :xs="12" :sm="12" :lg="12" style="text-align: right;">
|
||||||
<a-icon type="sync" :spin="refreshing" @click="refreshOutboundTraffic()" style="margin: 0 5px;"/>
|
<a-icon type="sync" :spin="refreshing" @click="refreshOutboundTraffic()" style="margin: 0 5px;"></a-icon>
|
||||||
|
<a-icon type="retweet" @click="resetOutboundTraffic(-1)"></a-icon>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
<a-table :columns="outboundColumns" bordered
|
<a-table :columns="outboundColumns" bordered
|
||||||
|
@ -408,6 +410,11 @@
|
||||||
<a-icon type="edit"></a-icon>
|
<a-icon type="edit"></a-icon>
|
||||||
{{ i18n "edit" }}
|
{{ i18n "edit" }}
|
||||||
</a-menu-item>
|
</a-menu-item>
|
||||||
|
<a-menu-item @click="resetOutboundTraffic(index)">
|
||||||
|
<span>
|
||||||
|
<a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic"}}
|
||||||
|
</span>
|
||||||
|
</a-menu-item>
|
||||||
<a-menu-item @click="deleteOutbound(index)">
|
<a-menu-item @click="deleteOutbound(index)">
|
||||||
<span style="color: #FF4D4F">
|
<span style="color: #FF4D4F">
|
||||||
<a-icon type="delete"></a-icon> {{ i18n "delete"}}
|
<a-icon type="delete"></a-icon> {{ i18n "delete"}}
|
||||||
|
@ -947,6 +954,16 @@
|
||||||
this.refreshing = false;
|
this.refreshing = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async resetOutboundTraffic(index) {
|
||||||
|
let tag = "-alltags-";
|
||||||
|
if (index >= 0) {
|
||||||
|
tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
|
||||||
|
}
|
||||||
|
const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
|
||||||
|
if (msg.success) {
|
||||||
|
await this.refreshOutboundTraffic();
|
||||||
|
}
|
||||||
|
},
|
||||||
addBalancer() {
|
addBalancer() {
|
||||||
balancerModal.show({
|
balancerModal.show({
|
||||||
title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
|
title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
|
||||||
|
|
|
@ -78,3 +78,25 @@ func (s *OutboundService) GetOutboundsTraffic() ([]*model.OutboundTraffics, erro
|
||||||
|
|
||||||
return traffics, nil
|
return traffics, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *OutboundService) ResetOutboundTraffic(tag string) error {
|
||||||
|
db := database.GetDB()
|
||||||
|
|
||||||
|
whereText := "tag "
|
||||||
|
if tag == "-alltags-" {
|
||||||
|
whereText += " <> ?"
|
||||||
|
} else {
|
||||||
|
whereText += " = ?"
|
||||||
|
}
|
||||||
|
|
||||||
|
result := db.Model(model.OutboundTraffics{}).
|
||||||
|
Where(whereText, tag).
|
||||||
|
Updates(map[string]interface{}{"up": 0, "down": 0, "total": 0})
|
||||||
|
|
||||||
|
err := result.Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue