Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzack99s committed Sep 10, 2020
2 parents b075259 + 4f16433 commit de510eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WSL2-forwarding-port-cli is command line tools for wsl2 forwarding port configur
1. Open WSL2 with Run Administrator
2. Download the binary with the command
```
curl -LO https://github.com/mrzack99s/wsl2-forwarding-port-cli/releases/download/v1.0.0/wfp-cli
curl -LO https://github.com/mrzack99s/wsl2-forwarding-port-cli/releases/download/v1.1.0/wfp-cli
```
3. Make the kubectl binary executable.
```
Expand Down
7 changes: 4 additions & 3 deletions cmds/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

func Lists() {
fmt.Printf("%-10s%-15s%-10s%-10s%-10s\n", "ID", "WSL2 IPADDR", "PROTOCOL", "SPORT", "DPORT")
fmt.Println("-------------------------------------------------------")
fmt.Println("--------------------------------------------------------------------")
fmt.Printf("%-10s%-22s%-12s%-12s%-12s\n", "ID", "WSL2 IPADDR", "PROTOCOL", "SPORT", "DPORT")
fmt.Println("--------------------------------------------------------------------")
if len(configs.RulesTable.Rules) > 0 {
for _, rule := range configs.RulesTable.Rules {
fmt.Printf("%-10s%-15s%-10s%-10s%-10s\n", rule.Id, rule.IpAddress, rule.Protocol, rule.SourcePort, rule.DestinationPort)
fmt.Printf("%-10s%-22s%-10s%-10s%-10s\n", rule.Id, rule.IpAddress, rule.Protocol, rule.SourcePort, rule.DestinationPort)
}
}

Expand Down
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func asSha256(o interface{}) string {
return fmt.Sprintf("%x", h.Sum(nil))
}

func checkAlreadyRule(id string) bool {
func checkAlreadyRuleByID(id string) bool {
for _, rule := range configs.RulesTable.Rules {
if id == rule.Id {
return true
Expand All @@ -52,6 +52,15 @@ func checkAlreadyRule(id string) bool {
return false
}

func checkAlreadyRuleBySPortAndProto(port string, proto string) bool {
for _, rule := range configs.RulesTable.Rules {
if port == rule.SourcePort && proto == rule.Protocol {
return true
}
}
return false
}

func main() {

if len(os.Args) < 2 {
Expand Down Expand Up @@ -105,7 +114,7 @@ func main() {
hash := asSha256(rule)
substringhash := hash[:8]

if !checkAlreadyRule(substringhash) {
if !checkAlreadyRuleByID(substringhash) && !checkAlreadyRuleBySPortAndProto(rule.SourcePort, rule.Protocol) {
status := cmds.CreateRule(createArgs, ip)
if status {
rule.Id = substringhash
Expand All @@ -123,7 +132,7 @@ func main() {

id := os.Args[2]

if checkAlreadyRule(id) {
if checkAlreadyRuleByID(id) {
index, status := cmds.DeleteRule(id)
if status {
length := len(configs.RulesTable.Rules)
Expand Down

0 comments on commit de510eb

Please sign in to comment.