diff --git a/.gitignore b/.gitignore index c2e2db9..2918140 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# Ignore all +* + +# Unignore all with extensions +!*.* + # ---> Go # If you prefer the allow list template instead of the deny list, see community template: # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore diff --git a/server/ghostrunner-server b/server/ghostrunner-server deleted file mode 100755 index 012b409..0000000 Binary files a/server/ghostrunner-server and /dev/null differ diff --git a/server/src/modules/database/handlers.go b/server/src/modules/database/handlers.go index ae72d15..98bcf4f 100644 --- a/server/src/modules/database/handlers.go +++ b/server/src/modules/database/handlers.go @@ -92,16 +92,12 @@ func RetrieveTokenNames() []string { } func InsertTask(name, command string, nodeids []string, date, status string) error { - pNodeIds, err := json.Marshal(nodeids) - if err != nil { - return err + for _, singleNodeid := range nodeids { + _, err := db.Exec(declStat.CreateTask, name, command, string(singleNodeid), date, status) + if err != nil { + return fmt.Errorf("failed to create task: %w", err) + } } - - _, err = db.Exec(declStat.CreateTask, name, command, string(pNodeIds), date, status) - if err != nil { - return fmt.Errorf("failed to create task: %w", err) - } - return nil } diff --git a/server/src/modules/database/statements.go b/server/src/modules/database/statements.go index 4d3f7b4..29c7a40 100644 --- a/server/src/modules/database/statements.go +++ b/server/src/modules/database/statements.go @@ -24,11 +24,12 @@ var declStat = Statements{ ); CREATE TABLE IF NOT EXISTS tasks ( id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT UNIQUE NOT NULL, + name TEXT NOT NULL, command TEXT NOT NULL, - nodeids TEXT NOT NULL, + nodeid TEXT NOT NULL, creation TEXT NOT NULL, - status TEXT NOT NULL + status TEXT NOT NULL, + result TEXT DEFAULT NULL );`, AdminTokenCreate: ` @@ -49,10 +50,10 @@ var declStat = Statements{ SELECT name FROM tokens`, CreateTask: ` - INSERT INTO tasks (name, command, nodeids, creation, status) + INSERT INTO tasks (name, command, nodeid, creation, status) VALUES (?, ?, ?, ?, ?);`, DeleteTask: ` DELETE FROM tasks WHERE name = ?;`, ListAllTasks: ` - Select name, command, nodeids, creation, status from tasks;`, + Select name, command, nodeid, creation, status from tasks;`, } diff --git a/server/src/modules/restapi/handlers.go b/server/src/modules/restapi/handlers.go index 9b868ed..8509940 100644 --- a/server/src/modules/restapi/handlers.go +++ b/server/src/modules/restapi/handlers.go @@ -242,6 +242,12 @@ func listTasksHandler(hmacKey []byte) http.HandlerFunc { } } +func flushTaskListHandler(hmacKey []byte) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + log.Println("skibidi") + } +} + func createTask(taskName, command string, nodeids []string) error { creationDate := time.Now().Format("02-01-2006 15:04:05") creationStatus := constCreationStatus diff --git a/server/src/modules/restapi/init.go b/server/src/modules/restapi/init.go index bcbc7ed..da1f356 100644 --- a/server/src/modules/restapi/init.go +++ b/server/src/modules/restapi/init.go @@ -64,6 +64,7 @@ func createRouter(hmacKey []byte) *mux.Router { r.HandleFunc("/task/create", createTaskHandler(hmacKey)).Methods("POST") r.HandleFunc("/task/delete", deleteTaskHandler(hmacKey)).Methods("DELETE") r.HandleFunc("/task/list", listTasksHandler(hmacKey)).Methods("GET") + r.HandleFunc("/task/flush", flushTaskListHandler(hmacKey)).Methods("DELETE") return r } diff --git a/server/src/modules/timekeeper/routine.go b/server/src/modules/timekeeper/routine.go index 11f10ea..f10aa96 100644 --- a/server/src/modules/timekeeper/routine.go +++ b/server/src/modules/timekeeper/routine.go @@ -10,15 +10,14 @@ func routine(cfg utilities.ConfigStruct, pyListArgs []string) { d := listDevices(cfg, pyListArgs) // Retrieve the Online devices. curTasks := database.RetrieveTasks() - for index, device := range d.OnlineDevices { - log.Println(index, device) - } - for index, task := range curTasks { - log.Println(index, task) - for _, nodeid := range task.Nodeids { + relevantNodeids := task.Nodeids + + log.Printf("Processing Task %d", index) + for _, nodeid := range relevantNodeids { if isNodeOnline(nodeid, d.OnlineDevices) { - log.Printf("NodeID %s is online\n", nodeid) + //result := wrapper.ExecCommand(nodeid, task.Command) + log.Printf("Node online: %s", nodeid) } } } diff --git a/server/src/modules/wrapper/python.go b/server/src/modules/wrapper/python.go index e2cd1a7..334046f 100644 --- a/server/src/modules/wrapper/python.go +++ b/server/src/modules/wrapper/python.go @@ -20,7 +20,6 @@ func PyListOnline(venvName string, pyArgs []string) (utilities.PyOnlineDevices, cmd := exec.Command(pyBin, runtimeArgs...) rawData, err := cmd.CombinedOutput() - log.Println(string(rawData)) if err != nil { cwd, _ := os.Getwd() return utilities.PyOnlineDevices{}, fmt.Errorf("python execution failed, working directory: %s", cwd) @@ -33,3 +32,7 @@ func PyListOnline(venvName string, pyArgs []string) (utilities.PyOnlineDevices, return data, nil } + +func ExecCommand(nodeid, command string) { + log.Printf("Triggered %s, on %s", command, nodeid) +}