Skip to content

Commit

Permalink
Fix ufw exec file presence check
Browse files Browse the repository at this point in the history
  • Loading branch information
peltho committed Jan 29, 2025
1 parent e26e3e4 commit 2546fe9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cmd/tufw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func main() {
log.Fatal("This program must be run as root! (sudo)")
}

cmd = exec.Command("ufw", "status")
_, err = cmd.Output()
if err != nil {
log.Fatal("Cannot find ufw. Is it installed?")
}

tui := service.CreateApplication()
tui.Init()
data, err := tui.LoadTableData()
Expand Down
32 changes: 14 additions & 18 deletions internal/core/service/tufw.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,24 +460,20 @@ func (t *Tui) Build(data []string) {
root := t.CreateLayout()

if len(data) <= 1 {
if len(data) == 1 && strings.Contains(data[0], "inactive") {
t.pages.HidePage("base")
t.CreateModal("ufw is disabled.\nDo you want to enable it?",
func() {
utils.Shellout("ufw --force enable")
},
func() {
t.app.Stop()
},
func() {
t.pages.HidePage("modal")
t.pages.ShowPage("base")
t.app.SetFocus(t.menu)
},
)
} else {
panic("ufw is not installed.\nBe sure to install it before launching tufw")
}
t.pages.HidePage("base")
t.CreateModal("ufw is disabled.\nDo you want to enable it?",
func() {
utils.Shellout("ufw --force enable")
},
func() {
t.app.Stop()
},
func() {
t.pages.HidePage("modal")
t.pages.ShowPage("base")
t.app.SetFocus(t.menu)
},
)
}

t.CreateTable(data)
Expand Down

0 comments on commit 2546fe9

Please sign in to comment.