Init commit

Resolved conflict
This commit is contained in:
Daan Selen
2025-05-13 16:59:07 +02:00
parent d6b4f272e7
commit a2ba67eb26
11 changed files with 97 additions and 2 deletions

View File

@@ -1,3 +1,9 @@
# ghostrunner
# GhostRunner
Defered MeshCentral Command Runner
This project aims to create a way to schedule commands to be run as soon as possible when they offline initialy.<br>
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.<br>
Python executor/runner which actually executes the commands, Python was chosen because of the availability of: [LibMeshCtrl Python Library](https://pypi.org/project/libmeshctrl/).<br>

1
runner/requirements.txt Normal file
View File

@@ -0,0 +1 @@
libmeshctrl==1.2.0

9
runner/runner.py Normal file
View File

@@ -0,0 +1,9 @@
#!/bin/python3
import meshctrl
def main():
print("Hello World")
if __name__ == "__main__":
main()

1
server/SERVER.md Normal file
View File

@@ -0,0 +1 @@
# Go Backend Server Information.

5
server/src/go.mod Normal file
View File

@@ -0,0 +1,5 @@
module ghostrunner-server
go 1.24.3
require github.com/gorilla/mux v1.8.1

2
server/src/go.sum Normal file
View File

@@ -0,0 +1,2 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=

5
server/src/main.go Normal file
View File

@@ -0,0 +1,5 @@
package main
func main() {
}

View File

View File

@@ -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.
}
}

View File

@@ -0,0 +1,6 @@
package restapi
type infoResponse struct {
Status int `json:"status"`
Message string `json:"message"`
}

View File

@@ -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
}