diff --git a/README.md b/README.md index c7b86e1..509f928 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ -# ghostrunner +# GhostRunner -Defered MeshCentral Command Runner \ No newline at end of file +This project aims to create a way to schedule commands to be run as soon as possible when they offline initialy.
+The way to accomplish this is to create a tracked task list, and keep track of it has been successfully done. + +# Technical details. + +Go(lang) backend server which exposes an HTTP API which can be used to add tasks to the process.
+Python executor/runner which actually executes the commands, Python was chosen because of the availability of: [LibMeshCtrl Python Library](https://pypi.org/project/libmeshctrl/).
diff --git a/runner/requirements.txt b/runner/requirements.txt new file mode 100644 index 0000000..2411e25 --- /dev/null +++ b/runner/requirements.txt @@ -0,0 +1 @@ +libmeshctrl==1.2.0 \ No newline at end of file diff --git a/runner/runner.py b/runner/runner.py new file mode 100644 index 0000000..adf3763 --- /dev/null +++ b/runner/runner.py @@ -0,0 +1,9 @@ +#!/bin/python3 + +import meshctrl + +def main(): + print("Hello World") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/server/SERVER.md b/server/SERVER.md new file mode 100644 index 0000000..3fe7634 --- /dev/null +++ b/server/SERVER.md @@ -0,0 +1 @@ +# Go Backend Server Information. \ No newline at end of file diff --git a/server/src/go.mod b/server/src/go.mod new file mode 100644 index 0000000..10b8cc7 --- /dev/null +++ b/server/src/go.mod @@ -0,0 +1,5 @@ +module ghostrunner-server + +go 1.24.3 + +require github.com/gorilla/mux v1.8.1 diff --git a/server/src/go.sum b/server/src/go.sum new file mode 100644 index 0000000..7128337 --- /dev/null +++ b/server/src/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/server/src/main.go b/server/src/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/server/src/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/server/src/modules/restapi/handlers.go b/server/src/modules/restapi/handlers.go new file mode 100644 index 0000000..e69de29 diff --git a/server/src/modules/restapi/init.go b/server/src/modules/restapi/init.go new file mode 100644 index 0000000..f9381b2 --- /dev/null +++ b/server/src/modules/restapi/init.go @@ -0,0 +1,46 @@ +package restapi + +import ( + "crypto/tls" + "encoding/json" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +const ( + defaultMessage = "GhostRunner Server, HTTP REST API. Version: 0.0.1." +) + +func rootEndpointHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + log.Println("ROOT HIT") //Comment out later, for debugging purposes + json.NewEncoder(w).Encode(infoResponse{ + Status: http.StatusOK, + Message: defaultMessage, + }) +} + +func _initApiServer(secureServer bool, apiKey, apiCert, apiPort string) { + apiRouter := mux.NewRouter().StrictSlash(true) // Initialize the HTTP REST API Router. + + apiRouter.HandleFunc("/", rootEndpointHandler).Methods("GET") + + if secureServer { // If a secured server is wanted. Use the specified certificate files. + httpServer := &http.Server{ + Addr: apiPort, // Specify the desired HTTPS port. + Handler: apiRouter, // Specify the above created handler. + TLSConfig: &tls.Config{ + Certificates: []tls.Certificate{ // Load the certificate and private key. + loadTLSCertificate(apiCert, apiKey), + }, + }, + } + go httpServer.ListenAndServeTLS("", "") + } else { + go http.ListenAndServe(":"+apiPort, apiRouter) // Transform string slightly to make the expected format. + } +} diff --git a/server/src/modules/restapi/structs.go b/server/src/modules/restapi/structs.go new file mode 100644 index 0000000..e84e4f9 --- /dev/null +++ b/server/src/modules/restapi/structs.go @@ -0,0 +1,6 @@ +package restapi + +type infoResponse struct { + Status int `json:"status"` + Message string `json:"message"` +} diff --git a/server/src/modules/restapi/utilities.go b/server/src/modules/restapi/utilities.go new file mode 100644 index 0000000..a5bd490 --- /dev/null +++ b/server/src/modules/restapi/utilities.go @@ -0,0 +1,14 @@ +package restapi + +import ( + "crypto/tls" + "log" +) + +func loadTLSCertificate(certFile, keyFile string) tls.Certificate { + cert, err := tls.LoadX509KeyPair(certFile, keyFile) + if err != nil { + log.Fatal(err) + } + return cert +}