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-03-17 22:37:52 +0300
committerGitHub <noreply@github.com>2023-03-17 22:37:52 +0300
commit8c6c9ace792bdeae739ef028261eb5fd5eaafb8a (patch)
tree6c74658bdee39da7f5b5f8a5984a5ea803934e4a
parentd46e0e69251d0ad60adc614505bcabff99529e1e (diff)
parentf881c5347c86a885b7167b9207fa2ea8dd6f9d24 (diff)
Merge pull request #29 from MHSanaei/ClientIPs-functions
Client ips functions
-rw-r--r--web/html/xui/client_modal.html4
-rw-r--r--web/html/xui/form/client.html4
-rw-r--r--web/html/xui/form/protocol/trojan.html23
-rw-r--r--web/html/xui/form/protocol/vless.html23
-rw-r--r--web/html/xui/form/protocol/vmess.html23
-rw-r--r--web/service/inbound.go52
6 files changed, 52 insertions, 77 deletions
diff --git a/web/html/xui/client_modal.html b/web/html/xui/client_modal.html
index 17381a88..e4ee8659 100644
--- a/web/html/xui/client_modal.html
+++ b/web/html/xui/client_modal.html
@@ -120,12 +120,12 @@
event.target.value = msg.obj
}
},
- async clearDBClientIps(email,event) {
+ async clearDBClientIps(email) {
const msg = await HttpUtil.post('/xui/inbound/clearClientIps/'+ email);
if (!msg.success) {
return;
}
- event.target.value = ""
+ document.getElementById("clientIPs").value = ""
},
},
});
diff --git a/web/html/xui/form/client.html b/web/html/xui/form/client.html
index 586f4fd4..fac830e2 100644
--- a/web/html/xui/form/client.html
+++ b/web/html/xui/form/client.html
@@ -50,12 +50,12 @@
Clear The Log
</template>
<span style="color: #FF4D4F">
- <a-icon type="delete" @click="clearDBClientIps(client.email,$event)"></a-icon>
+ <a-icon type="delete" @click="clearDBClientIps(client.email)"></a-icon>
</span>
</a-tooltip>
</span>
<a-form layout="block">
- <a-textarea readonly @click="getDBClientIps(client.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 2, maxRows: 10 }">
+ <a-textarea id="clientIPs" readonly @click="getDBClientIps(client.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 2, maxRows: 10 }">
</a-textarea>
</a-form>
</a-form-item>
diff --git a/web/html/xui/form/protocol/trojan.html b/web/html/xui/form/protocol/trojan.html
index 76cc9b66..840ce17d 100644
--- a/web/html/xui/form/protocol/trojan.html
+++ b/web/html/xui/form/protocol/trojan.html
@@ -31,29 +31,6 @@
</span>
<a-input type="number" v-model.number="client.limitIp" min="0" style="width: 70px;" ></a-input>
</a-form-item>
- <a-form-item v-if="client.email && client.limitIp > 0 && isEdit">
- <span slot="label">
- IP log
- <a-tooltip>
- <template slot="title">
- IPs history Log (before enabling inbound after it has been disabled by IP limit, you should clear the log)
- </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(client.email,$event)"></a-icon>
- </span>
- </a-tooltip>
- </span>
- <a-form layout="block">
- <a-textarea readonly @click="getDBClientIps(client.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 2, maxRows: 10 }">
- </a-textarea>
- </a-form>
- </a-form-item>
<a-form-item v-if="inbound.XTLS" label="Flow">
<a-select v-model="client.flow" style="width: 150px">
<a-select-option value="">{{ i18n "none" }}</a-select-option>
diff --git a/web/html/xui/form/protocol/vless.html b/web/html/xui/form/protocol/vless.html
index 146587f7..6b3436f0 100644
--- a/web/html/xui/form/protocol/vless.html
+++ b/web/html/xui/form/protocol/vless.html
@@ -31,29 +31,6 @@
</span>
<a-input type="number" v-model.number="client.limitIp" min="0" style="width: 70px;" ></a-input>
</a-form-item>
- <a-form-item v-if="client.email && client.limitIp > 0 && isEdit">
- <span slot="label">
- IP log
- <a-tooltip>
- <template slot="title">
- IPs history Log (before enabling inbound after it has been disabled by IP limit, you should clear the log)
- </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(client.email,$event)"></a-icon>
- </span>
- </a-tooltip>
- </span>
- <a-form layout="block">
- <a-textarea readonly @click="getDBClientIps(client.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 2, maxRows: 10 }">
- </a-textarea>
- </a-form>
- </a-form-item>
<a-form-item v-if="inbound.XTLS" label="Flow">
<a-select v-model="inbound.settings.vlesses[index].flow" style="width: 150px">
<a-select-option value="" selected>{{ i18n "none" }}</a-select-option>
diff --git a/web/html/xui/form/protocol/vmess.html b/web/html/xui/form/protocol/vmess.html
index 4c6779dd..59cf6d2b 100644
--- a/web/html/xui/form/protocol/vmess.html
+++ b/web/html/xui/form/protocol/vmess.html
@@ -34,29 +34,6 @@
</span>
<a-input type="number" v-model.number="client.limitIp" min="0" style="width: 70px;"></a-input>
</a-form-item>
- <a-form-item v-if="client.email && client.limitIp > 0 && isEdit">
- <span slot="label">
- IP Log
- <a-tooltip>
- <template slot="title">
- IPs history Log (before enabling inbound after it has been disabled by IP limit, you should clear the log)
- </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(client.email,$event)"></a-icon>
- </span>
- </a-tooltip>
- </span>
- <a-form layout="block">
- <a-textarea readonly @click="getDBClientIps(client.email,$event)" placeholder="Click To Get IPs" :auto-size="{ minRows: 2, maxRows: 10 }">
- </a-textarea>
- </a-form>
- </a-form-item>
<a-form-item>
<span slot="label">
<span >{{ i18n "pages.inbounds.totalFlow" }}</span>(GB)
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 87440c84..b6f4f031 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -179,6 +179,20 @@ func (s *InboundService) DelInbound(id int) error {
if err != nil {
return err
}
+ inbound, err := s.GetInbound(id)
+ if err != nil {
+ return err
+ }
+ clients, err := s.getClients(inbound)
+ if err != nil {
+ return err
+ }
+ for _, client := range clients {
+ err := s.DelClientIPs(db, client.Email)
+ if err != nil {
+ return err
+ }
+ }
return db.Delete(model.Inbound{}, id).Error
}
@@ -286,6 +300,12 @@ func (s *InboundService) DelInboundClient(inbound *model.Inbound, email string)
oldInbound.Settings = inbound.Settings
+ err = s.DelClientIPs(db, email)
+ if err != nil {
+ logger.Error("Error in delete client IPs")
+ return err
+ }
+
return db.Save(oldInbound).Error
}
@@ -319,12 +339,26 @@ func (s *InboundService) UpdateInboundClient(inbound *model.Inbound, index int)
if len(clients[index].Email) > 0 {
if len(oldClients[index].Email) > 0 {
- s.UpdateClientStat(oldClients[index].Email, &clients[index])
+ err = s.UpdateClientStat(oldClients[index].Email, &clients[index])
+ if err != nil {
+ return err
+ }
+ err = s.UpdateClientIPs(db, oldClients[index].Email, clients[index].Email)
+ if err != nil {
+ return err
+ }
} else {
s.AddClientStat(inbound.Id, &clients[index])
}
} else {
- s.DelClientStat(db, oldClients[index].Email)
+ err = s.DelClientStat(db, oldClients[index].Email)
+ if err != nil {
+ return err
+ }
+ err = s.DelClientIPs(db, oldClients[index].Email)
+ if err != nil {
+ return err
+ }
}
return db.Save(oldInbound).Error
}
@@ -483,10 +517,20 @@ func (s *InboundService) UpdateClientStat(email string, client *model.Client) er
}
return nil
}
+
+func (s *InboundService) UpdateClientIPs(tx *gorm.DB, oldEmail string, newEmail string) error {
+ return tx.Model(model.InboundClientIps{}).Where("client_email = ?", oldEmail).Update("client_email", newEmail).Error
+}
+
func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error {
return tx.Where("email = ?", email).Delete(xray.ClientTraffic{}).Error
}
+func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error {
+ logger.Warning(email)
+ return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).Error
+}
+
func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error {
db := database.GetDB()
@@ -567,6 +611,7 @@ func (s *InboundService) SearchClientTraffic(query string) (traffic *xray.Client
}
return traffic, err
}
+
func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error) {
db := database.GetDB()
InboundClientIps := &model.InboundClientIps{}
@@ -576,7 +621,7 @@ func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error)
}
return InboundClientIps.Ips, nil
}
-func (s *InboundService) ClearClientIps(clientEmail string) (error) {
+func (s *InboundService) ClearClientIps(clientEmail string) error {
db := database.GetDB()
result := db.Model(model.InboundClientIps{}).
@@ -584,7 +629,6 @@ func (s *InboundService) ClearClientIps(clientEmail string) (error) {
Update("ips", "")
err := result.Error
-
if err != nil {
return err
}