Skip to content

Commit 4593ad1

Browse files
committed
20230502
1 parent 8adf81d commit 4593ad1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1387
-178
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ _output
2121
1
2222
.idea
2323
*.db
24+
main

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
## Fiewall Gateway Uranus
1+
# Uranus
22

3-
Firewalld gateway Uranus is a Linux firewalld central controller. In Greek mythology, Uranus king of gods. The firewall gateway is the Uranus for iptables.
3+
Uranus is a Linux firewalld central controller. In Greek mythology, Uranus king of gods. The firewall gateway is the Uranus for iptables.
44

5-
## Features
5+
## Show
6+
7+
[Click](#Screenshot)
68

7-
- Full firewalld features (currently only covert Redhat7)
9+
## Features
10+
- Full firewalld features (currently converted OS debian11, centos7)
811
- Full D-BUS API convert to REST API.
912
- Based dbus remotely.
1013
- HTTP restful API.
@@ -25,11 +28,12 @@ Firewalld gateway Uranus is a Linux firewalld central controller. In Greek mytho
2528
- [X] optional API on (v3 only)
2629
- [X] security policy
2730
- [X] Delay task
28-
- [ ] UI doing
31+
- [X] UI
2932
- [X] Authtication.
33+
- [X] Deplyment on Kubernetes & Docker
3034
- [ ] Prometheus Metics.
3135
- [ ] WAF SDK.
32-
- [X] Deplyment on Kubernetes
36+
- [ ] Token destory
3337

3438

3539
## Deploy
@@ -113,4 +117,18 @@ To edit /etc/dbus-1/system.conf, example.
113117
-v 5 // full log
114118
-v 4 // info log
115119
-v 2 // no log
116-
```
120+
```
121+
122+
## Screenshot
123+
124+
![](./images/123.png)
125+
126+
![](./images/223.png)
127+
128+
![](./images/323.png)
129+
130+
![](./images/423.png)
131+
132+
![](./images/523.png)
133+
134+
![](./images/623.png)

apis/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ const (
9393
CONFIG_ZONE_QUERYFORWARDPORT = CONFIG_ZONE + ".queryForwardPort"
9494
CONFIG_GETFORWARDPORT = CONFIG_ZONE + ".getForwardPorts"
9595
CONFIG_REMOVEZONE = CONFIG_ZONE + ".remove"
96+
CONFIG_DEFAULT_POLICY = CONFIG_ZONE + ".getTarget"
9697
)

apis/firewalld_types.go

Lines changed: 83 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,25 @@ type Log struct {
5656
Level string `form:"level" json:"level,omitempty"`
5757
Limit Limit `form:"limit" json:"limit,omitempty"`
5858
}
59+
60+
type Value struct {
61+
Value string `form:"value" json:"value,omitempty"`
62+
}
63+
5964
type Limit struct {
6065
Value string `form:"value" json:"value,omitempty"`
6166
}
6267
type Audit struct {
6368
Limit Limit `form:"limit" json:"limit,omitempty"`
6469
}
6570
type Accept struct {
66-
Flag bool
67-
Limit Limit `form:"limit" json:"limit,omitempty"`
71+
Flag bool `form:"flag" json:"flag,omitempty"`
6872
}
6973
type Reject struct {
70-
Type string `form:"type" json:"type,omitempty"`
71-
Limit Limit `form:"limit" json:"limit,omitempty"`
74+
Flag bool `form:"flag" json:"flag,omitempty"`
7275
}
7376
type Drop struct {
74-
Flag bool
75-
Limit Limit `form:"limit" json:"limit,omitempty"`
77+
Flag bool
7678
}
7779

7880
type Mark struct {
@@ -86,11 +88,11 @@ type SourcePort struct {
8688
}
8789

8890
type Rule struct {
89-
Family string `form:"family" json:"family,omitempty,default=ipv4"`
91+
Family string `form:"family" json:"family,omitempty"`
9092
Source *Source `form:"source" json:"source,omitempty"`
9193
Destination *Destination `form:"destination" json:"destination,omitempty"`
9294
Service []string `form:"service" json:"service,omitempty"`
93-
Port *Port `form:"protocol" json:"protocol,omitempty"`
95+
Port *Port `form:"port" json:"port,omitempty"`
9496
Protocol *Protocol `form:"protocol" json:"protocol,omitempty"`
9597
IcmpBlock *IcmpBlock `form:"icmpblock" json:"icmpblock,omitempty"`
9698
IcmpType *IcmpType `form:"icmptype" json:"icmptype,omitempty"`
@@ -101,6 +103,8 @@ type Rule struct {
101103
Reject *Reject `form:"reject" json:"reject,omitempty"`
102104
Drop *Drop `form:"drop" json:"drop,omitempty"`
103105
Mark *Mark `form:"mark" json:"mark,omitempty"`
106+
Limit *Limit `form:"limit" json:"limit,omitempty"`
107+
Value *Value `form:"value" json:"value,omitempty"`
104108
}
105109

106110
type Interface struct {
@@ -168,8 +172,8 @@ type Settings struct {
168172
IcmpBlockInversion bool `deepcopier:"field:IcmpBlockInversion" form:"icmp-block-inversion" json:"icmp-block-inversion",omitempty"`
169173
}
170174

171-
func (this *Source) IsEmpty() bool {
172-
return this == nil
175+
func (s *Source) IsEmpty() bool {
176+
return s == nil
173177
}
174178

175179
func (this *Destination) IsEmpty() bool {
@@ -224,13 +228,18 @@ func (this *Limit) IsEmpty() bool {
224228
return this == nil
225229
}
226230

231+
func (this *Value) IsEmpty() bool {
232+
return this == nil
233+
}
234+
227235
func (this *Source) ToString() string {
236+
228237
var str = " source "
229238
if this.Address != "" {
230239
str += "address=" + this.Address
231240
} else if this.Mac != "" {
232241
str += "mac=" + this.Mac
233-
} else {
242+
} else if this.Ipset != "" {
234243
str += "ipset=" + this.Ipset
235244
}
236245
if this.Invert != "" {
@@ -257,18 +266,19 @@ func (this *Destination) ToString() string {
257266
func (this *Port) ToString() string {
258267
var str = "port "
259268
if this.Port != "" {
260-
str += "name=" + this.Port
269+
str += "port=" + this.Port
261270
}
262271
if this.Protocol != "" {
263-
str += "protocol=" + this.Protocol
272+
273+
str += " " + "protocol=" + this.Protocol
264274
}
265275

266276
str += " "
267277
return str
268278
}
269279

270280
func (this *Protocol) ToString() string {
271-
var str = "Protocol "
281+
var str = "protocol "
272282
if this.Value != "" {
273283
str += "value=" + this.Value
274284
}
@@ -337,7 +347,6 @@ func (this *Log) ToString() string {
337347
if !this.Limit.IsEmpty() {
338348
str += " " + "limit value=" + this.Limit.Value
339349
}
340-
341350
str += " "
342351
return str
343352
}
@@ -353,32 +362,42 @@ func (this *Audit) ToString() string {
353362
return str
354363
}
355364

365+
func (this *Limit) ToString() string {
366+
var str string
367+
if !this.IsEmpty() {
368+
str += "limit value=" + this.Value
369+
}
370+
str += " "
371+
return str
372+
}
373+
356374
func (this *Accept) ToString() string {
357375
var str string
358376

359377
if this.Flag {
360378
str = "accept "
361379
}
362-
if !this.Limit.IsEmpty() {
363-
str += "limit value=" + this.Limit.Value
364-
}
365-
366380
str += " "
367381
return str
368382
}
369383

370384
func (this *Reject) ToString() string {
371-
var str = "reject "
385+
var str string
372386

373-
if this.Type != "" {
374-
str += "type=" + this.Type
387+
if !this.IsEmpty() {
388+
str = "reject "
375389
}
376390

377-
if !this.Limit.IsEmpty() {
378-
str += " "
379-
str += "limit value=" + this.Limit.Value
380-
}
391+
str += " "
392+
return str
393+
}
381394

395+
func (this *Value) ToString() string {
396+
var str = "value= "
397+
398+
if !this.IsEmpty() {
399+
str += "type=" + this.Value
400+
}
382401
str += " "
383402
return str
384403
}
@@ -389,9 +408,6 @@ func (this *Drop) ToString() string {
389408
if this.Flag {
390409
str = "drop "
391410
}
392-
if !this.Limit.IsEmpty() {
393-
str += "limit value=" + this.Limit.Value
394-
}
395411
str += " "
396412
return str
397413
}
@@ -415,8 +431,9 @@ func (this *Mark) ToString() string {
415431

416432
func (this *Rule) ToString() (ruleString string) {
417433
ruleString = "rule "
434+
418435
if this.Family != "" {
419-
ruleString += "family=" + this.Family
436+
ruleString += "family=" + this.Family + " "
420437
}
421438

422439
if !this.Source.IsEmpty() {
@@ -520,27 +537,21 @@ func SliceToStruct(array interface{}) (ForwardPort, error) {
520537
return ForwardPort{}, encounterError
521538
}
522539

523-
func stringToReject(slice []string) (reject *Reject, ruleSlice []string) {
524-
Label:
525-
for index, value := range slice {
526-
tmp_slice := strings.Split(value, "=")
527-
switch tmp_slice[1] {
528-
case "type":
529-
slice = removeSliceElement(slice, index)
530-
reject.Type = slice[index]
531-
slice = removeSliceElement(slice, index)
532-
goto Label
533-
case "limit":
534-
slice = removeSliceElement(slice, index)
535-
tmp_slice := strings.Split(slice[index], "=")
536-
reject.Limit = Limit{Value: tmp_slice[1]}
537-
slice = removeSliceElement(slice, index)
538-
goto Label
539-
}
540-
}
541-
ruleSlice = slice
542-
return reject, ruleSlice
543-
}
540+
//func stringToReject(slice []string) (reject *Reject, ruleSlice []string) {
541+
//Label:
542+
// for index, value := range slice {
543+
// tmp_slice := strings.Split(value, "=")
544+
// switch tmp_slice[1] {
545+
// case "type":
546+
// slice = removeSliceElement(slice, index)
547+
// reject.Type = slice[index]
548+
// slice = removeSliceElement(slice, index)
549+
// goto Label
550+
// }
551+
// }
552+
// ruleSlice = slice
553+
// return reject, ruleSlice
554+
//}
544555

545556
func stringToMark(slice []string) (mark *Mark, ruleSlice []string) {
546557

@@ -619,18 +630,18 @@ Label:
619630
}
620631

621632
func StringToRule(str string) (rule *Rule) {
622-
623633
strslice := strings.Split(str, " ")
624634
rule = &Rule{}
625635
Label:
626636
for index, value := range strslice {
627637
switch value {
628638
case "rule":
629639
strslice = removeSliceElement(strslice, index)
640+
goto Label
641+
case `family="ipv4"`, `family="ipv6"`:
630642
tmp_str := strings.Split(strslice[index], "=")
631643
rule.Family = tmp_str[1]
632644
strslice = removeSliceElement(strslice, index)
633-
goto Label
634645
case "source":
635646
strslice = removeSliceElement(strslice, index)
636647
tmp_str := strings.Split(strslice[index], "=")
@@ -676,10 +687,11 @@ Label:
676687
Protocol: protocol[1],
677688
}
678689
strslice = removeSliceElement(strslice, index)
690+
strslice = removeSliceElement(strslice, index)
679691
goto Label
680692
case "protocol":
681693
strslice = removeSliceElement(strslice, index)
682-
tmp_str := strings.Split(strslice[index+1], "=")
694+
tmp_str := strings.Split(strslice[index], "=")
683695
rule.Protocol = &Protocol{Value: tmp_str[1]}
684696
strslice = removeSliceElement(strslice, index)
685697
goto Label
@@ -711,39 +723,37 @@ Label:
711723
goto Label
712724
case "accept":
713725
strslice = removeSliceElement(strslice, index)
714-
accept := &Accept{}
715-
rule.Accept = accept
716-
rule.Accept.Flag = true
717-
var tmp_str []string
718-
if len(strslice) > 0 {
719-
if strslice[index] == "limit" {
720-
strslice = removeSliceElement(strslice, index)
721-
tmp_str = strings.Split(strslice[index], "=")
722-
rule.Accept.Limit = Limit{Value: tmp_str[1]}
723-
}
726+
rule.Accept = &Accept{
727+
Flag: true,
724728
}
725729
goto Label
726730
case "drop":
727-
var tmp_str []string
728731
strslice = removeSliceElement(strslice, index)
729-
rule.Drop.Flag = true
730-
if len(strslice) > 0 {
731-
if strslice[index] == "limit" {
732-
strslice = removeSliceElement(strslice, index)
733-
tmp_str = strings.Split(strslice[index], "=")
734-
rule.Drop.Limit = Limit{Value: tmp_str[1]}
735-
}
732+
rule.Drop = &Drop{
733+
Flag: true,
736734
}
737735
goto Label
738736
case "reject":
739737
strslice = removeSliceElement(strslice, index)
740-
rule.Reject, strslice = stringToReject(strslice)
738+
rule.Reject = &Reject{}
741739
goto Label
742740
case "mark":
743741
strslice = removeSliceElement(strslice, index)
744742
rule.Mark, strslice = stringToMark(strslice)
745743
goto Label
744+
case "limit":
745+
var tmp_str []string
746+
strslice = removeSliceElement(strslice, index)
747+
tmp_str = strings.Split(strslice[index], "=")
748+
rule.Limit = &Limit{Value: tmp_str[1]}
749+
goto Label
750+
case "value":
751+
strslice = removeSliceElement(strslice, index)
752+
rule.Value = &Value{
753+
Value: strslice[index],
754+
}
746755
}
756+
747757
}
748758
return rule
749759
}

db/ModelOptions.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

images/123.png

21.6 KB
Loading

images/223.png

14.4 KB
Loading

images/323.png

7.13 KB
Loading

images/423.png

14 KB
Loading

images/523.png

11.9 KB
Loading

0 commit comments

Comments
 (0)