Skip to content

Commit

Permalink
ip limit only if log is available
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Mar 12, 2024
1 parent e7ae846 commit 18af704
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions web/html/xui/form/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</template>
<a-input v-model.trim="client.tgId"></a-input>
</a-form-item>
<a-form-item>
<a-form-item v-if="app.ipLimitEnable">
<template slot="label">
<a-tooltip>
<template slot="title">
Expand All @@ -75,7 +75,7 @@
</template>
<a-input-number v-model="client.limitIp" min="0"></a-input-number>
</a-form-item>
<a-form-item v-if="client.email && client.limitIp > 0 && isEdit">
<a-form-item v-if="app.ipLimitEnable && client.email && isEdit">
<template slot="label">
<a-tooltip>
<template slot="title">
Expand Down
2 changes: 2 additions & 0 deletions web/html/xui/inbounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@
datepicker: 'gregorian',
tgBotEnable: false,
showAlert: false,
ipLimitEnable: false,
pageSize: 0,
isMobile: window.innerWidth <= 768,
},
Expand Down Expand Up @@ -618,6 +619,7 @@
this.pageSize = pageSize;
this.remarkModel = remarkModel;
this.datepicker = datepicker;
this.ipLimitEnable = ipLimitEnable;
}
},
setInbounds(dbInbounds) {
Expand Down
42 changes: 31 additions & 11 deletions web/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,25 @@ func (s *SettingService) SetWarp(data string) error {
return s.setString("warp", data)
}

func (s *SettingService) GetIpLimitEnable() (bool, error) {
templateConfig, err := s.GetXrayConfigTemplate()
if err != nil {
return false, err
}

var xrayConfig map[string]interface{}
err = json.Unmarshal([]byte(templateConfig), &xrayConfig)
if err != nil {
return false, err
}
if logConfig, ok := xrayConfig["log"].(map[string]interface{}); ok {
if accessLogPath, ok := logConfig["access"].(string); ok {
return accessLogPath == "./access.log", nil
}
}
return false, nil
}

func (s *SettingService) UpdateAllSetting(allSetting *entity.AllSetting) error {
if err := allSetting.CheckValid(); err != nil {
return err
Expand Down Expand Up @@ -492,17 +511,18 @@ func (s *SettingService) GetDefaultXrayConfig() (interface{}, error) {
func (s *SettingService) GetDefaultSettings(host string) (interface{}, error) {
type settingFunc func() (interface{}, error)
settings := map[string]settingFunc{
"expireDiff": func() (interface{}, error) { return s.GetExpireDiff() },
"trafficDiff": func() (interface{}, error) { return s.GetTrafficDiff() },
"pageSize": func() (interface{}, error) { return s.GetPageSize() },
"defaultCert": func() (interface{}, error) { return s.GetCertFile() },
"defaultKey": func() (interface{}, error) { return s.GetKeyFile() },
"tgBotEnable": func() (interface{}, error) { return s.GetTgbotenabled() },
"subEnable": func() (interface{}, error) { return s.GetSubEnable() },
"subURI": func() (interface{}, error) { return s.GetSubURI() },
"subJsonURI": func() (interface{}, error) { return s.GetSubJsonURI() },
"remarkModel": func() (interface{}, error) { return s.GetRemarkModel() },
"datepicker": func() (interface{}, error) { return s.GetDatepicker() },
"expireDiff": func() (interface{}, error) { return s.GetExpireDiff() },
"trafficDiff": func() (interface{}, error) { return s.GetTrafficDiff() },
"pageSize": func() (interface{}, error) { return s.GetPageSize() },
"defaultCert": func() (interface{}, error) { return s.GetCertFile() },
"defaultKey": func() (interface{}, error) { return s.GetKeyFile() },
"tgBotEnable": func() (interface{}, error) { return s.GetTgbotenabled() },
"subEnable": func() (interface{}, error) { return s.GetSubEnable() },
"subURI": func() (interface{}, error) { return s.GetSubURI() },
"subJsonURI": func() (interface{}, error) { return s.GetSubJsonURI() },
"remarkModel": func() (interface{}, error) { return s.GetRemarkModel() },
"datepicker": func() (interface{}, error) { return s.GetDatepicker() },
"ipLimitEnable": func() (interface{}, error) { return s.GetIpLimitEnable() },
}

result := make(map[string]interface{})
Expand Down

2 comments on commit 18af704

@MHKRG
Copy link

@MHKRG MHKRG commented on 18af704 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

سلام تو Xray Configuration اینو اضافه کردی ؟

"log": {
"access": "./access.log",
"dnsLog": false,
"loglevel": "warning"
},

@aminkhandan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

سلام
آیا میشه برای تانل هم ip limit ست کرد؟

Please sign in to comment.