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:
authorMasoud Hidden <130294836+masoud-hidden@users.noreply.github.com>2023-11-20 17:17:59 +0300
committerGitHub <noreply@github.com>2023-11-20 17:17:59 +0300
commitabc590ae715d13aac60398c99aaa34ab43b06c42 (patch)
tree6aa182fa869b579cd67e9a1caa5fd055b027305f /web/service/inbound.go
parentad6d07326a6b23fd0e54446a24bf537de4dba4e1 (diff)
[bot] Some new features for telegram bot (#1241)
* [bot] Some new features for telegram bot +Ability to set traffic limit for client. +Custom input for reset expire days. +Custom input for reset IP limit. +Added refresh time to the client ip log message. * [bot] fix translations
Diffstat (limited to 'web/service/inbound.go')
-rw-r--r--web/service/inbound.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index a9ac8d0e..1646b5ed 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -1231,6 +1231,67 @@ func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry
return nil
}
+func (s *InboundService) ResetClientTrafficLimitByEmail(clientEmail string, totalGB int) error {
+ if totalGB < 0 {
+ return common.NewError("totalGB must be >= 0")
+ }
+ _, inbound, err := s.GetClientInboundByEmail(clientEmail)
+ if err != nil {
+ return err
+ }
+ if inbound == nil {
+ return common.NewError("Inbound Not Found For Email:", clientEmail)
+ }
+
+ oldClients, err := s.GetClients(inbound)
+ if err != nil {
+ return err
+ }
+
+ clientId := ""
+
+ for _, oldClient := range oldClients {
+ if oldClient.Email == clientEmail {
+ if inbound.Protocol == "trojan" {
+ clientId = oldClient.Password
+ } else {
+ clientId = oldClient.ID
+ }
+ break
+ }
+ }
+
+ if len(clientId) == 0 {
+ return common.NewError("Client Not Found For Email:", clientEmail)
+ }
+
+ var settings map[string]interface{}
+ err = json.Unmarshal([]byte(inbound.Settings), &settings)
+ if err != nil {
+ return err
+ }
+ clients := settings["clients"].([]interface{})
+ var newClients []interface{}
+ for client_index := range clients {
+ c := clients[client_index].(map[string]interface{})
+ if c["email"] == clientEmail {
+ c["totalGB"] = totalGB * 1024 * 1024 * 1024
+ newClients = append(newClients, interface{}(c))
+ }
+ }
+ settings["clients"] = newClients
+ modifiedSettings, err := json.MarshalIndent(settings, "", " ")
+ if err != nil {
+ return err
+ }
+ inbound.Settings = string(modifiedSettings)
+ _, err = s.UpdateInboundClient(inbound, clientId)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error {
db := database.GetDB()