inital commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# Sample Go WASM Plugin (sample)
|
||||
|
||||
This sample lives at the repo root and builds a WASI-compatible Go plugin.
|
||||
|
||||
## Files to include in the plugin zip
|
||||
|
||||
At the root of the zip:
|
||||
- sample.wasm
|
||||
- sample.html
|
||||
- sample.css
|
||||
- sample.js
|
||||
|
||||
## Build the WASM
|
||||
|
||||
Recommended: Go WASI (most compatible with wazero)
|
||||
|
||||
1) Build the WASM with Go 1.21+:
|
||||
|
||||
GOOS=wasip1 GOARCH=wasm go build -o sample.wasm ./wasm
|
||||
|
||||
2) Optional TinyGo fallback:
|
||||
|
||||
tinygo build -o sample.wasm -target wasi -scheduler=none -gc=leaking ./wasm
|
||||
|
||||
## Create the zip
|
||||
|
||||
Create a zip named sample.zip containing:
|
||||
- sample.wasm
|
||||
- sample.html
|
||||
- sample.css
|
||||
- sample.js
|
||||
|
||||
Then place sample.zip in Overlord-Server/plugins.
|
||||
|
||||
## Open the UI
|
||||
|
||||
Navigate to:
|
||||
- /plugins/sample?clientId=<CLIENT_ID>
|
||||
|
||||
Click "Send event" and the WASM plugin will echo back to the server logs.
|
||||
|
||||
## OS detection (Windows-only logic)
|
||||
|
||||
The plugin receives host metadata in the `init` payload. The sample plugin shows
|
||||
how to detect the host OS and branch logic (see
|
||||
[plugin-sample-go/wasm/main.go](plugin-sample-go/wasm/main.go)). For example:
|
||||
|
||||
- If `host.os == "windows"`, you can safely run Windows-only flows (e.g., WinAPI-backed behavior).
|
||||
- Otherwise, skip or provide a fallback path.
|
||||
@@ -0,0 +1,89 @@
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Segoe UI", system-ui, sans-serif;
|
||||
background: #0f1115;
|
||||
color: #e8ecf1;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 820px;
|
||||
margin: 40px auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0 0 4px 0;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.sub {
|
||||
margin: 0 0 24px 0;
|
||||
color: #9aa4b2;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #161a22;
|
||||
border: 1px solid #222938;
|
||||
border-radius: 12px;
|
||||
padding: 18px;
|
||||
margin-bottom: 18px;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: 120px 1fr;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: #9aa4b2;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.input {
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #2a3346;
|
||||
background: #0f131b;
|
||||
color: #e8ecf1;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: #3b82f6;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 10px 14px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.log {
|
||||
min-height: 120px;
|
||||
background: #0f131b;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #2a3346;
|
||||
padding: 12px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Sample Plugin</title>
|
||||
<link rel="stylesheet" href="/plugins/sample/assets/sample.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<header class="header">
|
||||
<h1>Sample Plugin</h1>
|
||||
<p class="sub">Go WASM + UI plugin</p>
|
||||
</header>
|
||||
|
||||
<section class="card">
|
||||
<div class="row">
|
||||
<label class="label">Client ID</label>
|
||||
<input id="client-id" class="input" placeholder="clientId" />
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="label">Message</label>
|
||||
<input id="message" class="input" placeholder="hello from UI" />
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="label">Message Box</label>
|
||||
<input id="msgbox" class="input" placeholder="Windows only" />
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button id="send-btn" class="btn">Send event to client</button>
|
||||
<button id="ping-btn" class="btn">Ping Test x100</button>
|
||||
<button id="msgbox-btn" class="btn">Show Message Box</button>
|
||||
<button id="run-cmd-btn" class="btn">Run Command (example)</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Log</h2>
|
||||
<pre id="log" class="log"></pre>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="/plugins/sample/assets/sample.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,103 @@
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const clientIdInput = document.getElementById("client-id");
|
||||
const messageInput = document.getElementById("message");
|
||||
const msgBoxInput = document.getElementById("msgbox");
|
||||
const logEl = document.getElementById("log");
|
||||
const sendBtn = document.getElementById("send-btn");
|
||||
const pingBtn = document.getElementById("ping-btn");
|
||||
const msgBoxBtn = document.getElementById("msgbox-btn");
|
||||
const runCmdBtn = document.getElementById("run-cmd-btn");
|
||||
|
||||
const pluginId = "sample";
|
||||
const clientIdFromUrl = params.get("clientId") || "";
|
||||
clientIdInput.value = clientIdFromUrl;
|
||||
messageInput.value = "hello from sample UI";
|
||||
msgBoxInput.value = "Hello from Overlord";
|
||||
|
||||
function log(line) {
|
||||
const ts = new Date().toISOString();
|
||||
logEl.textContent = `${ts} ${line}\n` + logEl.textContent;
|
||||
}
|
||||
|
||||
async function sendEvent(event, payload) {
|
||||
const clientId = clientIdInput.value.trim();
|
||||
if (!clientId) {
|
||||
log("Missing clientId");
|
||||
return;
|
||||
}
|
||||
const res = await fetch(`/api/clients/${encodeURIComponent(clientId)}/plugins/${pluginId}/event`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ event, payload }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
log(`Send failed: ${res.status} ${text}`);
|
||||
return;
|
||||
}
|
||||
log(`Sent event: ${event}`);
|
||||
}
|
||||
|
||||
sendBtn.addEventListener("click", () => {
|
||||
const message = messageInput.value.trim();
|
||||
sendEvent("ui_message", { message });
|
||||
});
|
||||
|
||||
pingBtn?.addEventListener("click", async () => {
|
||||
const clientId = clientIdInput.value.trim();
|
||||
if (!clientId) {
|
||||
log("Missing clientId");
|
||||
return;
|
||||
}
|
||||
const res = await fetch(`/api/clients/${encodeURIComponent(clientId)}/command`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ action: "ping_bulk", count: 100 }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const msg = await res.text();
|
||||
log(`Ping test failed: ${msg}`);
|
||||
return;
|
||||
}
|
||||
log("Ping test x100 dispatched (single request)");
|
||||
});
|
||||
|
||||
msgBoxBtn?.addEventListener("click", async () => {
|
||||
const clientId = clientIdInput.value.trim();
|
||||
if (!clientId) {
|
||||
log("Missing clientId");
|
||||
return;
|
||||
}
|
||||
const text = msgBoxInput.value.trim() || "Hello from Overlord";
|
||||
const script = `$os = $env:OS; if ($os -ne 'Windows_NT') { exit } ; Add-Type -AssemblyName PresentationFramework; [System.Windows.MessageBox]::Show('${text.replace(/'/g, "''")}') | Out-Null`;
|
||||
const res = await fetch(`/api/clients/${encodeURIComponent(clientId)}/command`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ action: "script_exec", script, scriptType: "powershell" }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const msg = await res.text();
|
||||
log(`Message box failed: ${msg}`);
|
||||
return;
|
||||
}
|
||||
log("Message box command sent (Windows only)");
|
||||
});
|
||||
|
||||
runCmdBtn?.addEventListener("click", async () => {
|
||||
const clientId = clientIdInput.value.trim();
|
||||
if (!clientId) {
|
||||
log("Missing clientId");
|
||||
return;
|
||||
}
|
||||
const res = await fetch(`/api/clients/${encodeURIComponent(clientId)}/command`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ action: "screenshot" }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const msg = await res.text();
|
||||
log(`Command failed: ${msg}`);
|
||||
return;
|
||||
}
|
||||
log("Command sent: screenshot");
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
module plugin-sample-go/wasm
|
||||
|
||||
go 1.21
|
||||
|
||||
require github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
type Incoming struct {
|
||||
Type string `msgpack:"type"`
|
||||
Event string `msgpack:"event,omitempty"`
|
||||
Payload interface{} `msgpack:"payload,omitempty"`
|
||||
}
|
||||
|
||||
type Outgoing struct {
|
||||
Type string `msgpack:"type"`
|
||||
Event string `msgpack:"event,omitempty"`
|
||||
Payload interface{} `msgpack:"payload,omitempty"`
|
||||
}
|
||||
|
||||
type UiMessage struct {
|
||||
Message string `msgpack:"message"`
|
||||
}
|
||||
|
||||
type HostInfo struct {
|
||||
ClientID string `msgpack:"clientId"`
|
||||
OS string `msgpack:"os"`
|
||||
Arch string `msgpack:"arch"`
|
||||
Version string `msgpack:"version"`
|
||||
}
|
||||
|
||||
type InitPayload struct {
|
||||
Host HostInfo `msgpack:"host"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
dec := msgpack.NewDecoder(os.Stdin)
|
||||
enc := msgpack.NewEncoder(os.Stdout)
|
||||
|
||||
for {
|
||||
var msg Incoming
|
||||
if err := dec.Decode(&msg); err != nil {
|
||||
log.Printf("decode error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
switch msg.Type {
|
||||
case "init":
|
||||
var init InitPayload
|
||||
if payloadBytes, err := msgpack.Marshal(msg.Payload); err == nil {
|
||||
_ = msgpack.Unmarshal(payloadBytes, &init)
|
||||
}
|
||||
|
||||
osName := init.Host.OS
|
||||
if osName == "" {
|
||||
osName = "unknown"
|
||||
}
|
||||
|
||||
if osName == "windows" {
|
||||
log.Printf("[sample] windows detected - you can use WinAPI-specific flows")
|
||||
_ = enc.Encode(Outgoing{Type: "event", Event: "ready", Payload: "sample plugin ready (windows detected)"})
|
||||
} else {
|
||||
log.Printf("[sample] non-windows host detected (%s)", osName)
|
||||
_ = enc.Encode(Outgoing{Type: "event", Event: "ready", Payload: "sample plugin ready"})
|
||||
}
|
||||
case "event":
|
||||
if msg.Event == "ui_message" {
|
||||
payloadBytes, _ := msgpack.Marshal(msg.Payload)
|
||||
var ui UiMessage
|
||||
_ = msgpack.Unmarshal(payloadBytes, &ui)
|
||||
_ = enc.Encode(Outgoing{Type: "event", Event: "echo", Payload: ui.Message})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user