feat: basic binary execution
This commit is contained in:
+10
-12
@@ -33,22 +33,20 @@ func main() {
|
||||
w := app.NewWindow("PatchWorks")
|
||||
w.Resize(windowSize)
|
||||
|
||||
userEntry := widget.NewEntry()
|
||||
passEntry := widget.NewPasswordEntry()
|
||||
targEntry := widget.NewEntry()
|
||||
var book string
|
||||
|
||||
inputContainer := draw.MakeInputContainer(userEntry, passEntry, targEntry, &book, w)
|
||||
infoContainer := draw.MakeInfoContainer()
|
||||
|
||||
content := container.NewBorder(
|
||||
nil, // top
|
||||
nil, // bottom
|
||||
nil, // left
|
||||
nil, // right
|
||||
inputContainer, // center
|
||||
inputContainer := draw.MakeInput(targEntry, &book)
|
||||
footerContainer := draw.MakeFooter(targEntry, &book, app)
|
||||
|
||||
center := container.NewBorder(
|
||||
nil, // top
|
||||
footerContainer, // bottom
|
||||
nil, // left
|
||||
nil, // right
|
||||
inputContainer, // center
|
||||
)
|
||||
|
||||
w.SetContent(content)
|
||||
w.SetContent(center)
|
||||
w.ShowAndRun()
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ package draw
|
||||
import "fyne.io/fyne/v2"
|
||||
|
||||
var (
|
||||
entrySize fyne.Size = fyne.NewSize(300, 50)
|
||||
entrySize fyne.Size = fyne.NewSize(300, 50)
|
||||
buttonSize fyne.Size = fyne.NewSize(250, 50)
|
||||
)
|
||||
|
||||
+40
-15
@@ -8,24 +8,18 @@ import (
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
|
||||
runner "patchworks/src/modules/runner"
|
||||
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()
|
||||
if err != nil {
|
||||
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(
|
||||
widget.NewLabel("MeshCentral Target Device or Group"),
|
||||
widget.NewLabel("MeshCentral Target Group"),
|
||||
targEntry,
|
||||
)
|
||||
|
||||
@@ -51,15 +45,46 @@ func MakeInputContainer(userEntry, passEntry, targEntry *widget.Entry, book *str
|
||||
)
|
||||
|
||||
inputBox := container.New(
|
||||
layout.NewGridLayoutWithColumns(3),
|
||||
loginBox, // column 1
|
||||
targetBox, // column 2
|
||||
bookBox, // column 3
|
||||
layout.NewGridLayoutWithColumns(2),
|
||||
targetBox, // column 1
|
||||
bookBox, // column 2
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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, ""
|
||||
}
|
||||
@@ -24,7 +24,6 @@ func ListAvailableBooks() ([]string, error) {
|
||||
}
|
||||
|
||||
fName := f.Name()
|
||||
log.Println(fName)
|
||||
if isYaml(fName) {
|
||||
fullRelPath := "./books/" + fName
|
||||
foundBooks = append(foundBooks, fullRelPath)
|
||||
|
||||
Reference in New Issue
Block a user