feat: basic binary execution

This commit is contained in:
2026-03-30 23:16:48 +02:00
parent 5533e87bc9
commit 9b2eefcc52
5 changed files with 115 additions and 29 deletions
+9 -11
View File
@@ -33,22 +33,20 @@ func main() {
w := app.NewWindow("PatchWorks") w := app.NewWindow("PatchWorks")
w.Resize(windowSize) w.Resize(windowSize)
userEntry := widget.NewEntry()
passEntry := widget.NewPasswordEntry()
targEntry := widget.NewEntry() targEntry := widget.NewEntry()
var book string var book string
inputContainer := draw.MakeInputContainer(userEntry, passEntry, targEntry, &book, w) inputContainer := draw.MakeInput(targEntry, &book)
infoContainer := draw.MakeInfoContainer() footerContainer := draw.MakeFooter(targEntry, &book, app)
content := container.NewBorder( center := container.NewBorder(
nil, // top nil, // top
nil, // bottom footerContainer, // bottom
nil, // left nil, // left
nil, // right nil, // right
inputContainer, // center inputContainer, // center
) )
w.SetContent(content) w.SetContent(center)
w.ShowAndRun() w.ShowAndRun()
} }
+2 -1
View File
@@ -3,5 +3,6 @@ package draw
import "fyne.io/fyne/v2" import "fyne.io/fyne/v2"
var ( var (
entrySize fyne.Size = fyne.NewSize(300, 50) entrySize fyne.Size = fyne.NewSize(300, 50)
buttonSize fyne.Size = fyne.NewSize(250, 50)
) )
+40 -15
View File
@@ -8,24 +8,18 @@ import (
"fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
runner "patchworks/src/modules/runner"
tasks "patchworks/src/modules/tasks" tasks "patchworks/src/modules/tasks"
) )
func MakeInputContainer(userEntry, passEntry, targEntry *widget.Entry, book *string, win fyne.Window) *fyne.Container { func MakeInput(targEntry *widget.Entry, book *string) *fyne.Container {
availBooks, err := tasks.ListAvailableBooks() availBooks, err := tasks.ListAvailableBooks()
if err != nil { if err != nil {
log.Println("failed to read available books on disk") log.Println("failed to read available books on disk")
} }
loginBox := container.NewVBox(
widget.NewLabel("MeshCentral Username"),
userEntry,
widget.NewLabel("MeshCentral Password"),
passEntry,
)
targetBox := container.NewVBox( targetBox := container.NewVBox(
widget.NewLabel("MeshCentral Target Device or Group"), widget.NewLabel("MeshCentral Target Group"),
targEntry, targEntry,
) )
@@ -51,15 +45,46 @@ func MakeInputContainer(userEntry, passEntry, targEntry *widget.Entry, book *str
) )
inputBox := container.New( inputBox := container.New(
layout.NewGridLayoutWithColumns(3), layout.NewGridLayoutWithColumns(2),
loginBox, // column 1 targetBox, // column 1
targetBox, // column 2 bookBox, // column 2
bookBox, // column 3
) )
return inputBox return inputBox
} }
func MakeInfoContainer(book *string) *fyne.Container { func MakeFooter(targEntry *widget.Entry, book *string, app fyne.App) *fyne.Container {
actionBtn := widget.NewButton("Execute", func() {
log.Println("Beginning execution with external binary")
ok, path := runner.FindMeshbookBinary()
if !ok {
log.Println("something went wrong while looking for the binary, see above for details")
}
ok, result := runner.RunMeshbook(path, *book, targEntry.Text)
if !ok {
log.Println("something went wrong while running the meshbook, see above for details")
}
log.Println(result)
})
actionWrap := container.NewGridWrap(
buttonSize,
actionBtn,
)
cancelBtn := widget.NewButton("Exit", func() {
log.Println("Quitting")
app.Quit()
})
cancelWrap := container.NewGridWrap(
buttonSize,
cancelBtn,
)
bottomBox := container.NewHBox(
actionWrap, // left
layout.NewSpacer(), // flexible space
cancelWrap, // right
)
return bottomBox
} }
+63
View File
@@ -0,0 +1,63 @@
package runner
import (
"log"
"os"
"os/exec"
"runtime"
)
func FindMeshbookBinary() (bool, string) {
var osBin string
switch runtime.GOOS {
case "windows":
osBin = "meshbook.exe"
case "linux":
osBin = "meshbook"
default:
log.Println("undefined operating system")
}
log.Println("going to search for:", osBin)
binaryFound := false
var binaryPath string
for _, f := range []string{("./" + osBin), ("./bin/" + osBin)} {
objInfo, err := os.Stat(f)
if err == nil && objInfo.Mode().IsRegular() {
binaryFound = true
binaryPath = f
log.Printf("found binary at %s", f)
break
}
}
if binaryFound {
return true, binaryPath
} else {
return false, ""
}
}
func RunMeshbook(binPath, bookPath, targGroup string) (bool, string) {
var args []string
if len(bookPath) == 0 {
args = []string{"--help"}
} else {
args = []string{"--nograce", "-mb", bookPath, "--group", targGroup}
}
log.Printf("running with parameters: %v", args)
cmd := exec.Command(binPath, args...)
cOut, err := cmd.CombinedOutput()
if err != nil {
log.Printf("something went wrong when running the command: %v", err)
log.Printf("captured output: %s", string(cOut))
return false, ""
}
log.Printf("captured output: %s", string(cOut))
return true, ""
}
-1
View File
@@ -24,7 +24,6 @@ func ListAvailableBooks() ([]string, error) {
} }
fName := f.Name() fName := f.Name()
log.Println(fName)
if isYaml(fName) { if isYaml(fName) {
fullRelPath := "./books/" + fName fullRelPath := "./books/" + fName
foundBooks = append(foundBooks, fullRelPath) foundBooks = append(foundBooks, fullRelPath)