Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Dev patch 2 (#107)
Browse files Browse the repository at this point in the history
* [vmess] add client traffic reset

* [vless] add client traffic reset
  • Loading branch information
hossinasaadi authored Nov 22, 2022
1 parent 5bd865a commit 4421fec
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 78 deletions.
13 changes: 12 additions & 1 deletion web/controller/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {

g.POST("/clientIps/:email", a.getClientIps)
g.POST("/clearClientIps/:email", a.clearClientIps)
g.POST("/resetClientTraffic/:email", a.resetClientTraffic)


}
Expand Down Expand Up @@ -143,4 +144,14 @@ func (a *InboundController) clearClientIps(c *gin.Context) {
return
}
jsonMsg(c, "Log Cleared", nil)
}
}
func (a *InboundController) resetClientTraffic(c *gin.Context) {
email := c.Param("email")

err := a.inboundService.ResetClientTraffic(email)
if err != nil {
jsonMsg(c, "something worng!", err)
return
}
jsonMsg(c, "traffic reseted", nil)
}
88 changes: 50 additions & 38 deletions web/html/xui/form/protocol/vless.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
<a-tooltip>
<template slot="title">
clear the log
</template>
<span style="color: #FF4D4F">
<a-icon type="delete" @click="clearDBClientIps(vless.email,$event)"></a-icon>
</span>
</a-tooltip>
</span>
<a-form layout="block">

<a-textarea readonly @click="getDBClientIps(vless.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 0.5, maxRows: 10 }">
</a-textarea>

<a-button type="danger" @click="clearDBClientIps(vless.email,$event)" >clear log</a-button>
</a-form>
</a-form-item>
</a-form>
Expand Down Expand Up @@ -89,45 +95,51 @@
v-model="vless._expiryTime" style="width: 300px;"></a-date-picker>
</a-form-item>
<a-form layout="inline">
<a-tooltip v-if="vless._totalGB > 0">
<template slot="title">
reset traffic
</template>
<span style="color: #FF4D4F">
<a-icon type="delete" @click="resetClientTraffic(vless,$event)"></a-icon>
</span>
</a-tooltip>
<a-tag color="blue">[[ sizeFormat(getUpStats(vless.email)) ]] / [[ sizeFormat(getDownStats(vless.email)) ]]</a-tag>
<a-form v-if="vless._totalGB > 0">
<a-tag color="red">used : [[ sizeFormat(getUpStats(vless.email) + getDownStats(vless.email)) ]]</a-tag>
</a-form>
<a-tag v-if="vless._totalGB > 0" color="red">used : [[ sizeFormat(getUpStats(vless.email) + getDownStats(vless.email)) ]]</a-tag>
<a-tag>
<svg

@click="addClient(inbound.protocol,vless, inbound.settings.vlesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 22 22"
width="22"
height="22"
class="mt-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="green"
d="M11 11V7h2v4h4v2h-4v4h-2v-4H7v-2h4zm1 11C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16z"
/>
</svg>
</a-tag>
<a-tag v-show="inbound.settings.vlesses.length > 1">
<svg
@click="removeClient(index, inbound.settings.vlesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 22 22"
width="22"
height="22"
class="mt-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="#EC4899"
d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm0-9.414l2.828-2.829 1.415 1.415L13.414 12l2.829 2.828-1.415 1.415L12 13.414l-2.828 2.829-1.415-1.415L10.586 12 7.757 9.172l1.415-1.415L12 10.586z"
/>
</svg>
</a-tag>
</a-form>

<!--Add Svg Icon-->
<svg

@click="addClient(inbound.protocol,vless, inbound.settings.vlesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"
class="ml-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="green"
d="M11 11V7h2v4h4v2h-4v4h-2v-4H7v-2h4zm1 11C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16z"
/>
</svg>

<!--Remove Svg Icon-->
<svg
v-show="inbound.settings.vlesses.length > 1"
@click="removeClient(index, inbound.settings.vlesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"
class="ml-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="#EC4899"
d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm0-9.414l2.828-2.829 1.415 1.415L13.414 12l2.829 2.828-1.415 1.415L12 13.414l-2.828 2.829-1.415-1.415L10.586 12 7.757 9.172l1.415-1.415L12 10.586z"
/>
</svg>

</a-form>

Expand Down
92 changes: 53 additions & 39 deletions web/html/xui/form/protocol/vmess.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
<a-tooltip>
<template slot="title">
clear the log
</template>
<span style="color: #FF4D4F">
<a-icon type="delete" @click="clearDBClientIps(vmess.email,$event)"></a-icon>
</span>
</a-tooltip>
</span>

<a-textarea readonly @click="getDBClientIps(vmess.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 0.5, maxRows: 10 }">
</a-textarea>

<a-button type="danger" @click="clearDBClientIps(vmess.email,$event)" >clear log</a-button>
</a-form-item>

</a-form>
Expand Down Expand Up @@ -84,47 +90,55 @@
v-model="vmess._expiryTime" style="width: 300px;"></a-date-picker>
</a-form-item>
<a-form layout="inline">
<a-tooltip v-if="vmess._totalGB > 0">
<template slot="title">
reset traffic
</template>
<span style="color: #FF4D4F">
<a-icon type="delete" @click="resetClientTraffic(vmess,$event)"></a-icon>
</span>
</a-tooltip>
<a-tag color="blue">[[ sizeFormat(getUpStats(vmess.email)) ]] / [[ sizeFormat(getDownStats(vmess.email)) ]]</a-tag>
<a-form v-if="vmess._totalGB > 0">
<a-tag color="red">used : [[ sizeFormat(getUpStats(vmess.email) + getDownStats(vmess.email)) ]]</a-tag>
</a-form>
<a-tag v-if="vmess._totalGB > 0" color="red">used : [[ sizeFormat(getUpStats(vmess.email) + getDownStats(vmess.email)) ]]</a-tag>
<a-tag>
<!--Add Svg Icon-->
<svg

@click="addClient(inbound.protocol,vmess, inbound.settings.vmesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 22 22"
width="22"
height="22"
class="mt-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="green"
d="M11 11V7h2v4h4v2h-4v4h-2v-4H7v-2h4zm1 11C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16z"
/>
</svg>
</a-tag>
<a-tag v-show="inbound.settings.vmesses.length > 1">

<!--Remove Svg Icon-->
<svg
@click="removeClient(index, inbound.settings.vmesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 22 22"
width="22"
height="22"
class="mt-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="#EC4899"
d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm0-9.414l2.828-2.829 1.415 1.415L13.414 12l2.829 2.828-1.415 1.415L12 13.414l-2.828 2.829-1.415-1.415L10.586 12 7.757 9.172l1.415-1.415L12 10.586z"
/>
</svg>
</a-tag>
</a-form>

<!--Add Svg Icon-->
<svg

@click="addClient(inbound.protocol,vmess, inbound.settings.vmesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"
class="ml-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="green"
d="M11 11V7h2v4h4v2h-4v4h-2v-4H7v-2h4zm1 11C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16z"
/>
</svg>

<!--Remove Svg Icon-->
<svg
v-show="inbound.settings.vmesses.length > 1"
@click="removeClient(index, inbound.settings.vmesses)"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"
class="ml-2 cursor-pointer"
>
<path fill="none" d="M0 0h24v24H0z" />
<path
fill="#EC4899"
d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm0-9.414l2.828-2.829 1.415 1.415L13.414 12l2.829 2.828-1.415 1.415L12 13.414l-2.828 2.829-1.415-1.415L10.586 12 7.757 9.172l1.415-1.415L12 10.586z"
/>
</svg>
<!-- <a-divider style="height: 2px; background-color: #7e7e7e" /> -->

</a-collapse-panel>

</a-collapse>
Expand Down
18 changes: 18 additions & 0 deletions web/html/xui/inbound_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@
}
event.target.value = ""
},
async resetClientTraffic(client,event) {
const msg = await HttpUtil.post('/xui/inbound/resetClientTraffic/'+ client.email);
if (!msg.success) {
return;
}
clientStats = this.inbound.clientStats
if(clientStats.length > 0)
{
for (const key in clientStats) {
if (Object.hasOwnProperty.call(clientStats, key)) {
if(clientStats[key]['email'] == client.email){
clientStats[key]['up'] = 0
clientStats[key]['down'] = 0
}
}
}
}
},
isExpiry(index) {
return this.inbound.isExpiry(index)
},
Expand Down
16 changes: 16 additions & 0 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@ func (s *InboundService) ClearClientIps(clientEmail string) (error) {
err := result.Error


if err != nil {
return err
}
return nil
}
func (s *InboundService) ResetClientTraffic(clientEmail string) (error) {
db := database.GetDB()

result := db.Model(xray.ClientTraffic{}).
Where("email = ?", clientEmail).
Update("up", 0).
Update("down", 0)

err := result.Error


if err != nil {
return err
}
Expand Down

0 comments on commit 4421fec

Please sign in to comment.