Skip to content

Commit

Permalink
feat: add verbose mode for sites (#50)
Browse files Browse the repository at this point in the history
* feat: add verbose mode for sites

* Update SiteEditPage.js

* Update proxy.go

---------

Co-authored-by: Gucheng <[email protected]>
  • Loading branch information
love98ooo and nomeguy authored Aug 3, 2024
1 parent 7132267 commit 34b2278
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
35 changes: 18 additions & 17 deletions object/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,24 @@ type Site struct {
UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"`
DisplayName string `xorm:"varchar(100)" json:"displayName"`

Tag string `xorm:"varchar(100)" json:"tag"`
Domain string `xorm:"varchar(100)" json:"domain"`
OtherDomains []string `xorm:"varchar(500)" json:"otherDomains"`
NeedRedirect bool `json:"needRedirect"`
EnableWaf bool `json:"enableWaf"`
Rules []string `xorm:"varchar(500)" json:"wafRuleIds"`
Challenges []string `xorm:"mediumtext" json:"challenges"`
Host string `xorm:"varchar(100)" json:"host"`
Port int `json:"port"`
Hosts []string `xorm:"varchar(1000)" json:"hosts"`
SslMode string `xorm:"varchar(100)" json:"sslMode"`
SslCert string `xorm:"-" json:"sslCert"`
PublicIp string `xorm:"varchar(100)" json:"publicIp"`
Node string `xorm:"varchar(100)" json:"node"`
IsSelf bool `json:"isSelf"`
Status string `xorm:"varchar(100)" json:"status"`
Nodes []*Node `xorm:"mediumtext" json:"nodes"`
Tag string `xorm:"varchar(100)" json:"tag"`
Domain string `xorm:"varchar(100)" json:"domain"`
OtherDomains []string `xorm:"varchar(500)" json:"otherDomains"`
NeedRedirect bool `json:"needRedirect"`
EnableWaf bool `json:"enableWaf"`
DisableVerbose bool `json:"disableVerbose"`
Rules []string `xorm:"varchar(500)" json:"wafRuleIds"`
Challenges []string `xorm:"mediumtext" json:"challenges"`
Host string `xorm:"varchar(100)" json:"host"`
Port int `json:"port"`
Hosts []string `xorm:"varchar(1000)" json:"hosts"`
SslMode string `xorm:"varchar(100)" json:"sslMode"`
SslCert string `xorm:"-" json:"sslCert"`
PublicIp string `xorm:"varchar(100)" json:"publicIp"`
Node string `xorm:"varchar(100)" json:"node"`
IsSelf bool `json:"isSelf"`
Status string `xorm:"varchar(100)" json:"status"`
Nodes []*Node `xorm:"mediumtext" json:"nodes"`

CasdoorApplication string `xorm:"varchar(100)" json:"casdoorApplication"`
ApplicationObj *casdoorsdk.Application `xorm:"-" json:"applicationObj"`
Expand Down
8 changes: 5 additions & 3 deletions rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type Rule interface {
checkRule(expressions []*object.Expression, req *http.Request) (bool, string, string, error)
}

func CheckRules(wafRuleIds []string, r *http.Request) (string, string, error) {
rules := object.GetRulesByRuleIds(wafRuleIds)
for _, rule := range rules {
func CheckRules(ruleIds []string, r *http.Request) (string, string, error) {
rules := object.GetRulesByRuleIds(ruleIds)
for i, rule := range rules {
var ruleObj Rule
switch rule.Type {
case "User-Agent":
Expand All @@ -51,6 +51,8 @@ func CheckRules(wafRuleIds []string, r *http.Request) (string, string, error) {
if action == "Block" || action == "Drop" {
if rule.Reason != "" {
reason = rule.Reason
} else {
reason = fmt.Sprintf("hit rule %s: %s", ruleIds[i], reason)
}
return action, reason, nil
} else if action == "Allow" {
Expand Down
4 changes: 4 additions & 0 deletions service/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
return
}

if reason != "" && site.DisableVerbose {
reason = "the rule has been hit"
}

switch action {
case "", "Allow":
w.WriteHeader(http.StatusOK)
Expand Down
10 changes: 10 additions & 0 deletions web/src/SiteEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ class SiteEditPage extends React.Component {
}} />
</Col>
</Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={2}>
{i18next.t("site:Disable verbose")}:
</Col>
<Col span={1} >
<Switch checked={this.state.site.disableVerbose} onChange={checked => {
this.updateSiteField("disableVerbose", checked);
}} />
</Col>
</Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={2}>
{i18next.t("site:Challenges")}:
Expand Down

0 comments on commit 34b2278

Please sign in to comment.